• Hi everyone!
    While I do understand a little SQL syntax, I’m not a big expert, so when advanced stuff comes into the game, I start gasping a bit.

    I’m using the following query within, phpMyAdmin, to delete all duplicated posts:

    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

    But I would like to modify it, selecting only duplicated records from a given category.

    The following basic query, selects all records from a given category:

    SELECT * FROM wp_posts
    LEFT JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)
    LEFT JOIN wp_term_taxonomy ON(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
    WHERE
    (wp_term_taxonomy.term_id = 27)
    AND wp_term_taxonomy.taxonomy = 'category'

    How would you merge the two queries? Maybe with a nested query? Or?

    Thanks

  • The topic ‘Selecting duplicates posts from one category (SQL) or plugin’ is closed to new replies.