Sarwar Hasan
Sarwar Hasan

Reputation: 1641

Why the SQL shows MySQL Error?

Why this sql shows mysql error?

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'

error string

[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

Please Advice me.

Upvotes: 2

Views: 68

Answers (1)

juergen d
juergen d

Reputation: 204756

When using join in a delete statement you have to specify from which tables you want to 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'

Upvotes: 6

Related Questions