2013-06-25 75 views
2

爲什麼這個sql顯示mysql錯誤?爲什麼SQL顯示MySQL錯誤?

DELETE FROM wp_comments 
JOIN wp_commentmeta ON wp_comments.comment_id =wp_commentmeta.comment_id 
AND wp_commentmeta.meta_key = 'somekey'       
AND wp_comments.comment_post_ID = '1' 

錯誤字符串

[Err] 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 'INNER JOIN wp_commentmeta ON 
wp_comments.comment_id =wp_commentmeta.comment_id A' at line 2 

請諮詢我。

回答

6

當在delete語句中使用join你必須從你想刪除的表指定

DELETE c 
FROM wp_comments c 
JOIN wp_commentmeta m ON c.comment_id = m.comment_id 
         AND m.meta_key = 'somekey'       
         AND c.comment_post_ID = '1'