Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 6:36 pm
How would I (and this is just hypothetical) delete all from database where user_id != 1, 2, 3, 5, or 6
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Thu Jul 13, 2006 6:42 pm
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;
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Jul 13, 2006 6:46 pm
Code: Select all
DELETE FROM `users` WHERE `user_id` NOT IN (1, 2, 3, 5, 6 )
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Thu Jul 13, 2006 6:51 pm
I like that method better.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 6:52 pm
how do you make that SQL box like astions did? I tried [sql] and it didn't work.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Jul 13, 2006 6:54 pm
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.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 8:11 pm