Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    Need simple SQL Query

    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?

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SKDevelopment View Post
    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?

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    DELETE FROM `phpbb_users` WHERE `user_email` NOT IN ('info@xxx.com','info@aaaa.com','info@yahoo.com') OR `user_email` IS NULL;

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,394
    Thanks
    13
    Thanked 353 Times in 349 Posts
    [obsolete]
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #6
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SKDevelopment View Post
    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

  • #7
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    Quote Originally Posted by kevinkhan View Post
    DELETE FROM `phpbb_users` WHERE `user_email` NOT IN (

    (
    You have 2 "(" after "NOT IN". This causes the error.
    Last edited by SKDevelopment; 03-31-2010 at 10:39 AM.

  • Users who have thanked SKDevelopment for this post:

    kevinkhan (03-31-2010)

  • #8
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    That worked

    Thanks for your help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •