[英]Joining 3 tables in SQL table with COALESCE returning no results
我有以下查询,但没有返回任何结果。 所有表名和列均正确; 但是,无法使其返回结果。 我拿出主题表,它可以正常工作。 主题部分无法正常工作。 谁能发现这个问题? 表和列的名称正确。 这是我第一次使用COALESCE,但不确定是否正确使用它。
处理主题,这是我的目标:
如果draft_pages.theme = 0,我希望它改为从domain_profile.default_theme中提取值。 不确定COALESCE是否是正确的解决方案。
$getDRAFTinfo = $con->query("
SELECT
draft_pages.title,
draft_pages.url,
draft_pages.status,
draft_pages.modified,
draft_pages.modifier,
draft_pages.created,
draft_pages.creator,
draft_pages.domains,
COALESCE(draft_pages.theme, domain_profile.default_theme),
draft_pages.meta,
draft_pages.script,
draft_pages.page_lock,
draft_pages.design_lock,
themes.stylesheets,
domain_profile.default_theme
FROM draft_pages
JOIN domain_profile ON domain_profile.domain = '". $websitedomain ."'
JOIN themes ON themes.id = COALESCE(draft_pages.theme, domain_profile.default_theme)
WHERE draft_pages.id = '". $draftID ."'")
or die ('Unable to execute query. '. mysqli_error($con));
使用CASE
语句代替
case when draft_pages.theme = 0 then domain_profile.default_theme else draft_pages.theme end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.