2013-04-17 64 views
-1

手冊我有這樣的SQL查詢SQL錯誤:'您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法」

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 ] 

這個錯誤是什麼意思?

+3

您有多個'WHERE'關鍵字。第二個應該只是'和',而不是'和WHERE' –

+0

此錯誤意味着該SQL語句是如此畸形的解析器甚至不會嘗試給你關於如何解決它的具體意見。該錯誤是MySQL的分析器告訴你閱讀如何寫一個有效的SQL SELECT語句的手冊:http://dev.mysql.com/doc/refman/5.0/en/select.html –

+0

是杜佩:HTTP:/ /stackoverflow.com/questions/7884522/mysql-error-an-error-in-your-sql-syntax-check-the-manual-that-c​​orresponds-to –

回答

6

,因爲你有三個WHERE條款。如果您有多個條件,則需要使用條件運算符將它們分開,

SELECT ... 
FROM ... JOIN ... 
WHERE sites.deleted = 0 AND 
     categories.deleted = 0 AND 
     categories_data.deleted = 0 
GROUP BY sites.id 
相關問題