2013-01-22 72 views
1

我新的MySQL和我一直有這個問題的查詢。Mysql的多個連接語法錯誤

考慮這個查詢:

SELECT a.group_message_id, a.scheduled_date, b.message, c.phone_number, d.group_name 
    FROM schedule AS a 
    JOIN group_message AS b ON a.group_message_id = b.id, 
    JOIN phonenumber AS c ON c.id = a.phonenumber_id, 
    JOIN group_table AS d ON d.group_id = a.group_id 
    WHERE a.status = 'unsent' 

而且此錯誤消息:

您的SQL語法錯誤;檢查 對應於你的MySQL服務器版本正確的語法使用 接近「加入PHONENUMBER爲C ON c.id = a.phonenumber_id,JOIN group_table爲d」 4行

我需要手動幫助解決陳述中實際存在的問題。如果你能告訴我其他「正確」的方式,我也會很感激。

最後,只要沒有足夠的時間,是沒有辦法,我可以從MySQL的至少基本的學習有效的資源。請分享。

回答

5

去除加入語句逗號,

JOIN group_message AS b ON a.group_message_id = b.id, -- <<== HERE 
JOIN phonenumber AS c ON c.id = a.phonenumber_id,  -- <<== HERE 
JOIN group_table AS d ON d.group_id = a.group_id 

最後的查詢,

SELECT a.group_message_id, 
     a.scheduled_date, 
     b.message, 
     c.phone_number, 
     d.group_name 
FROM schedule AS a 
     JOIN group_message AS b 
      ON a.group_message_id = b.id 
     JOIN phonenumber AS c 
      ON c.id = a.phonenumber_id 
     JOIN group_table AS d 
      ON d.group_id = a.group_id 
WHERE a.status = 'unsent' 
1

你不應該把逗號

只是檢查語法here

樣品語法

SELECT column_list FROM table1 JOIN table2 ON condition JOIN table3 ON condition WHERE condition