SQL错误:'您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法'

时间:2013-04-17 15:40:41

标签: mysql sql

我有这个SQL查询

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
LEFT JOIN categories ON categories_data.categories_id = categories.id
WHERE sites.deleted=0 
AND WHERE categories.deleted=0 
AND WHERE categories_data.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 'WHERE categories.deleted=0 AND WHERE 
categories_data.deleted=0 GROUP BY sites.id' at line 5 [ 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 LEFT JOIN categories ON 
categories_data.categories_id = categories.id WHERE sites.deleted=0 
AND WHERE categories.deleted=0 AND WHERE categories_data.deleted=0 GROUP BY 
sites.id ]

这个错误是什么意思?

1 个答案:

答案 0 :(得分:6)

因为您有三个WHERE子句。如果您有多个条件,则需要使用条件运算符

将它们分开
SELECT ...
FROM   ... JOIN ...
WHERE  sites.deleted = 0 AND 
       categories.deleted = 0 AND 
       categories_data.deleted = 0 
GROUP  BY sites.id