• Hi All,

    I am looking to do a cleanup following 15,000+ users who shouldnt be there, however we have a management system with expiry dates, and just wanted to check this query for some opinion before making the changes.

    Obviously a backup would be useful before I press GO

    SELECT
    wp_users.user_login
    FROM
    wp_sbidManagement
    INNER JOIN wp_users ON wp_sbidManagement.<code>user</code> = wp_users.ID
    WHERE
    wp_sbidManagement.expiry_date < NOW() - INTERVAL 3 MONTH
    AND
    ID NOT IN
    (SELECT post_author FROM wp_posts
    UNION SELECT user_id FROM wp_comments);

    Followed by cleaning meta data

    SELECT *
    FROM wp_usermeta
    WHERE user_id NOT IN
    (SELECT ID FROM wp_users);

    Obviously once confirmed ill be taking a backup, then replacing “SELECT *” with DELETE.

    Best to ask before running.

  • The topic ‘Data Cleanup’ is closed to new replies.