2014-02-12 201 views
0

,所以我得到的這個sql查詢的錯誤,但我不能看到我的錯誤我自己:SQL查詢:連接兩個表

SELECT group_members.group_id, 
     group_members.permissions, 
     group.group_name 
    FROM group_members, 
     group 
WHERE group_members.group_id=group.group_id 
    AND group.group_id = 1 

錯誤:

#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 'group WHERE group_members.group_id=group.group_id AND group.group_id = 1 

感謝您的幫助!

+0

我認爲這是考慮「組」作爲關鍵字。嘗試使用'JOIN'來加入表格。 – user2989408

回答

3

集團是在MySQL中的保留字也括在反引號「`」或更好,但不要把它作爲一個表名

SELECT group_members.group_id, group_members.permissions, `group`.group_name 
FROM group_members, `group` 
WHERE group_members.group_id=`group`.group_id 
AND `group`.group_id = 1 
+0

感謝編輯戈登,有一個大腦放屁,不記得如何格式化查詢塊,只是看它時說它已被編輯 – Anigel

+0

謝謝:)問題解決了! – Jacob

1

試試這個

SELECT group_members.group_id, group_members.permissions, `group`.group_name 
FROM group_members, group 
WHERE group_members.group_id=`group`.group_id 
AND `group`.group_id = 1