...

View Full Version : Need simple SQL Query



kevinkhan
03-31-2010, 11:15 AM
How do i write a query to delete all records in a table but not records with a certain email address. I have this so far but it doesnt work :(

DELETE FROM `phpbb_users` WHERE `user_email` != (`info@xxx.com`,`info@aaaa.com`,`info@yahoo.com`)

can any body help me?

SKDevelopment
03-31-2010, 11:28 AM
DELETE FROM `phpbb_users` WHERE `user_email` NOT IN ('info@xxx.com','info@aaaa.com','info@yahoo.com')

Please notice that records where user_email is NULL will not be deleted.

kevinkhan
03-31-2010, 11:30 AM
DELETE FROM `phpbb_users` WHERE `user_email` NOT IN ('info@xxx.com','info@aaaa.com','info@yahoo.com')

Please notice that records where user_email is NULL will not be deleted.

How do i delete all records except for records with the above emails?

SKDevelopment
03-31-2010, 11:32 AM
DELETE FROM `phpbb_users` WHERE `user_email` NOT IN ('info@xxx.com','info@aaaa.com','info@yahoo.com') OR `user_email` IS NULL;

Dormilich
03-31-2010, 11:34 AM
[obsolete]

kevinkhan
03-31-2010, 11:34 AM
DELETE FROM `phpbb_users` WHERE `user_email` NOT IN ('info@xxx.com','info@aaaa.com','info@yahoo.com') OR `user_email` IS NULL;

Thanks for your help, Im getting this error tho

SQL query:

DELETE FROM `phpbb_users` WHERE `user_email` NOT IN (

(
'info@eurowebexperts.com',
'webmaster@adsindublin.com',
'info@djsindublin.com',
'kevinbobbyfoley@hotmail.com',
'maryahern232211@hotmail.com'
) OR `user_email` IS NULL
MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

SKDevelopment
03-31-2010, 11:37 AM
DELETE FROM `phpbb_users` WHERE `user_email` NOT IN (

(


You have 2 "(" after "NOT IN". This causes the error.

kevinkhan
03-31-2010, 11:41 AM
That worked :)

Thanks for your help ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum