我有這樣的SQL代碼如何在`JOIN`上使用`WHERE`?
SELECT sites.id, sites.url, GROUP_CONCAT(categories.name,"|",categories.color SEPARATOR ",") AS categories
FROM sites
LEFT JOIN categories_data ON sites.id = categories_data.sites_id WHERE categories_data.deleted=0
LEFT JOIN categories ON categories_data.categories_id = categories.id WHERE categories.deleted=0
WHERE sites.deleted=0 GROUP BY sites.id'
如果返回該錯誤
Database_Exception [ 1064 ]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN categories ON categories_data.categories_id = categories.id WHERE cate' at line 4 [ SELECT sites.id, sites.url, GROUP_CONCAT(categories.name,"|",categories.color SEPARATOR ",") AS categories FROM sites LEFT JOIN categories_data ON sites.id = categories_data.sites_id WHERE categories_data.deleted=0 LEFT JOIN categories ON categories_data.categories_id = categories.id WHERE categories.deleted=0 WHERE sites.deleted=0 GROUP BY sites.id ]
所以,我怎麼能在JOIN
使用WHERE
?
謝謝。
你不能在'join'上使用'where' –