Title: Data Cleanup
Last modified: August 21, 2016

---

# Data Cleanup

 *  [podman99](https://wordpress.org/support/users/podman99/)
 * (@podman99)
 * [12 years ago](https://wordpress.org/support/topic/data-cleanup/)
 * 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.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [delete](https://wordpress.org/support/topic-tag/delete/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [podman99](https://wordpress.org/support/users/podman99/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/data-cleanup/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
