为什么SQL显示MySQL错误?

时间:2013-06-25 18:17:32

标签: 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

请告诉我。

1 个答案:

答案 0 :(得分:6)

join语句中使用delete时,您必须指定要删除的表

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'