Reputation: 61
I downloaded and manually filtered a the Users database from Mysql, and now I have the users I don't want to delete. How should I make the query?
I have 100 users and I just want to keep User ID:1, 2, 6, 8, 19, 22, 30 and delete the rest.
Thanks in advance.
Upvotes: 0
Views: 317
Reputation: 1028
As you tagged it as a Wordpress, I assume you're using Wordpress.
Hence, Here's a solution you're looking for
$users = get_users();
$preserve_users = array(1,2,6,8,19,22,30); // IDs of users you want to preserve.
foreach($users as $user){
if ( !in_array( $user->ID, $preserve_users ) ) {
wp_delete_user( $user->ID ); // Delete user if not in a preserve user list
}
}
http://codex.wordpress.org/Function_Reference/wp_delete_user
Upvotes: 2
Reputation: 787
The answers above should do it but if you want a simple way to do it without the code then you will probably have phpmyadmin installed on your server. Go to yourdomain.com/phpmyadmin and login.
Then you can navigate to the wp_users table where you can pick and choose which users to keep. Down the bottom there's a select all and then you can just uncheck a few.
Upvotes: 0
Reputation: 859
Same as in SQL
DELETE FROM <table> WHERE Id NOT IN(<id's to keep>)
Upvotes: 0
Reputation: 12782
Use NOT IN
delete from Users where id not in (1,2,6,8,19,22,30);
Upvotes: 0