Reputation: 11
I have many articles which are duplicates, which means that one article is written more than one times. I have figured to find those using this MySQL command:
select post_title,post_content,count(*) as count from wp_posts
group by post_content
having count(*)>1
ORDER BY count(*) DESC
but, How can I delete only the duplicate posts, so that if any post has more than 1 copy, then only 1 copy will be left.
Any method would be appreciated.
Upvotes: 1
Views: 3427
Reputation: 3165
I advise backing up your SQL database before trying the below.
Try:
DELETE bad_rows . * FROM ktz3_posts AS bad_rows INNER JOIN (
SELECT post_title, MIN( id ) AS min_id
FROM ktz3_posts
GROUP BY post_title
HAVING COUNT( * ) >1
) AS good_rows ON good_rows.post_title = bad_rows.post_title
AND good_rows.min_id <> bad_rows.id
As the above code is untested, you could try the Duplicate Post Remover.
Upvotes: 4