I’m trying to run the sql query below but I’m getting a 505 error after some long time wait. The wp_posts table holds much more than 50,000 rows…the purpose being to remove duplicates posts which are about 50,000 rows
DELETE bad_rows.*
FROM wp_posts AS bad_rows
INNER JOIN
(
SELECT post_title, MIN(id) as min_id
FROM wp_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;
Any idea on how to have this optmized and run ?
Don’t think you need to use a sub-query. This will select all pairs of posts with the same titles.
If you want to keep the oldest post, delete all posts with id a.id. If you want to keep the newest post, delete all posts with id b.id.
So, to keep the oldest post:
To keep the newest post: