skarz
skarz

Reputation: 214

Need a MySQL query to delete duplicate comments

My wordpress site was recently hacked so I had to reinstall everything. Wordpress resinstalled, database backups imported, everything fine and dandy. Then I installed the Disqus plugin and synced (Disqus was previously used before the site was hacked). Big no-no apparantly. Now I have a duplicate of every single comment on my site! Even worse, the duplicate comments have been synced BACK to Disqus!

So, I know this is a simple query in PHPMyAdmin but I don't know it! Please help!

Upvotes: 0

Views: 472

Answers (1)

turbonerd
turbonerd

Reputation: 1306

D'oh, I just posted this as someone migrated it to SO...! Fortunately I have an account here too :)

FOR THE LOVE OF GOD BACK YOUR DATABASE UP FIRST

I haven't tried this query as I don't have a spare database to play around with.

This should help you though:

table1 = your table name
field_name = a field in your database.

DELETE FROM table1
USING table1, table1 as vtable
WHERE (NOT table1.ID=vtable.ID)
AND (table1.field_name=vtable.field_name)

As it's WordPress comments, presuming a prefix of wp, I'd probably recommend....

DELETE FROM wp_comments
USING wp_comments, wp_comments as vtable
WHERE (NOT wp_comments.ID=vtable.ID)
AND (wp_comments.comment_content=vtable.comment_content)

Hope that helps. Please read the note in bold before even contemplating running this query.

Upvotes: 2

Related Questions