0

我有三个非常简单的查询,我相信它们可以在一个查询中完成,但我无法弄清楚。以下是查询:

$idSQL = "SELECT website_id FROM websites WHERE website_url = :webURL LIMIT 1

$featureSQL = "SELECT feature_id FROM feature_website WHERE website_id = :webID";

$sql = "SELECT feature_name, feature_start, feature_end, feature_headline, feature_text,  feature_photoHor, feature_photoVert, feature_photoSquare FROM features WHERE feature_id = :featID";

这给了我预期的输出:在此处输入图像描述

因此,我尝试将查询(可能使用不正确的联接)组合成:

$sql = "SELECT f.feature_name, f.feature_start, f.feature_end, f.feature_headline, f.feature_text,  f.feature_photoHor, f.feature_photoVert, f.feature_photoSquare FROM features LEFT JOIN feature_website fw ON f.feature_id = fw.feature_id LEFT JOIN websites w ON fw.website_id = w.website_id AND w.website_url = :webURL";

我错过了什么?

4

1 回答 1

2

试试这个查询:

$sql = "
SELECT f.feature_name, f.feature_start, f.feature_end, f.feature_headline, f.feature_text,  f.feature_photoHor, f.feature_photoVert, f.feature_photoSquare 
FROM 
    websites w
        LEFT JOIN feature_website fw ON fw.website_id = w.website_id
        LEFT JOIN features f ON f.feature_id = fw.feature_id
WHERE
    w.website_url = :webURL
";

JOIN如果您的网站没有任何功能,如果您不想显示任何结果,也许您可​​以使用常规。

于 2013-04-25T19:48:09.320 回答