how do i select all the other entries other than specified in the list using IN

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepand
    New Member
    • Jun 2010
    • 1

    #1

    how do i select all the other entries other than specified in the list using IN

    I have to delete all entries other than specified using a IN statement. If my Mysql query is

    Code:
    SELECT * FROM `service' where id in (122,123,124,125);
    I want to select all the other entries with ids other than 122,123,124 and 125 and delete them.

    Thanks in advance.
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Originally posted by sandeepand
    I have to delete all entries other than specified using a IN statement. If my Mysql query is

    Code:
    SELECT * FROM `service' where id in (122,123,124,125);
    I want to select all the other entries with ids other than 122,123,124 and 125 and delete them.

    Thanks in advance.
    Hi there,
    You can use the NOT keyword before your IN.

    Code:
    SELECT * FROM `service' 
    WHERE id NOT IN (122,123,124,125);

    Comment

    Working...