0

The query below returns the second and subsequent post duplicates. Can someone better with SQL help me tweak the query to return all posts in a duplicate set? The reason is each duplicate set on my site must be manually reviewed. In some instances the initial post will be deleted. Thank you in advance!

SELECT a.ID, a.post_title, a.post_type, a.post_status
FROM wp_posts AS a
   INNER JOIN (
      SELECT post_title, MIN( id ) AS min_id
      FROM wp_posts
      WHERE post_type = 'gmo_article'
      AND post_status = 'publish'
      GROUP BY post_title
      HAVING COUNT( * ) > 1
   ) AS b ON b.post_title = a.post_title
AND b.min_id <> a.id
AND a.post_type = 'gmo_article'
AND a.post_status = 'publish'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.