我有一个嵌套的mysql_query。
$resultSub = mysql_query("SELECT *
FROM ensembles
WHERE en_name = $name
LEFT JOIN ensemble_names on ensembles.en_name = ensemble_names.en_nm_ID
LEFT JOIN students on ensembles.en_stu = students.s_ID
LEFT JOIN part_names on ensembles.en_part = part_names.p_nm_ID
ORDER BY $sort $orderBy");
在没有WHERE子句的情况下查询工作正常,我认为这可能会过滤掉LEFT JOIN
命令的行,但事实并非如此。
答案 0 :(得分:9)
WHERE子句应放在LEFT JOIN之后:
$resultSub = mysql_query("SELECT *
FROM ensembles
LEFT JOIN ensemble_names on ensembles.en_name = ensemble_names.en_nm_ID
LEFT JOIN students on ensembles.en_stu = students.s_ID
LEFT JOIN part_names on ensembles.en_part = part_names.p_nm_ID
WHERE en_name = $name
ORDER BY $sort $orderBy");
答案 1 :(得分:0)
好吧,你把WHERE
子句放在了错误的地方。