Page 1 of 1

DELETE ALL EXCEPT x

Posted: Thu Jul 13, 2006 6:36 pm
by Luke
How would I (and this is just hypothetical) delete all from database where user_id != 1, 2, 3, 5, or 6

Posted: Thu Jul 13, 2006 6:42 pm
by Benjamin

Code: Select all

delete from `users` where `user_id` != 1 and `user_id` != 2 and `user_id` != 3 and `user_id` != 4 and `user_id` != 5 and `user_id` != 6;

Posted: Thu Jul 13, 2006 6:46 pm
by hawleyjr

Code: Select all

DELETE FROM `users` WHERE `user_id` NOT IN (1, 2, 3, 5, 6 )

Posted: Thu Jul 13, 2006 6:51 pm
by Benjamin
I like that method better.

Posted: Thu Jul 13, 2006 6:52 pm
by Luke
how do you make that SQL box like astions did? I tried [sql] and it didn't work.

Posted: Thu Jul 13, 2006 6:54 pm
by hawleyjr
The Ninja Space Goat wrote:how do you make that SQL box like astions did? I tried [sql] and it didn't work.

[ syntax="sql" ]
delete from `users` where `user_id` != 1 and `user_id` != 2 and `user_id` != 3 and `user_id` != 4 and `user_id` != 5 and `user_id` != 6;
[ /syntax ]

Remove the space before/after the opening and closing [] of course.

Posted: Thu Jul 13, 2006 8:11 pm
by Luke

Code: Select all

 neat!