Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # NOTE
- # The records will be sorted by the post date, in ASCending order (newest to
- # oldest), which means posts created later are assumed as duplicates. Example
- # cases, where post-1 and post-2 have the *same slug* and created by the *same author*:
- # 1) post-1 created on Nov 1st; post-2 created on Nov 2nd; so post-2 is a duplicate.
- # 2) Same as #1 above, but post-2 was updated on Nov 3rd; so post-1 is a duplicate.
- # because the column post_date is changed when the post is created/updated.
- # Outer query - Select duplicate records.
- SELECT p.ID, p.post_author, p.post_name, p.post_type, p.post_status
- FROM wp_posts p
- INNER JOIN wp_posts p2 ON p2.post_author = p.post_author
- WHERE p.ID NOT IN (
- # Sub-query - Select original records.
- SELECT ID
- FROM wp_posts
- GROUP BY post_author, post_name
- HAVING ( COUNT(post_author) > 1 )
- AND ( COUNT(post_name) > 1 )
- # This should match the outer's ORDER BY
- ORDER BY post_date ASC
- )
- AND p.ID != p2.ID
- AND p.post_name = p2.post_name
- # This should match the sub-query's ORDER BY
- ORDER BY p.post_date ASC
- LIMIT 15
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement