Tono Nam
Tono Nam

Reputation: 36050

Opposite of IN operator in SQL

How could I do the opposite of:

example

In other words select all the people whose last name is NOT Hansen or Pettersen.

Upvotes: 10

Views: 20374

Answers (5)

patapizza
patapizza

Reputation: 2398

SELECT * FROM Persons WHERE LastName NOT IN ('Hansen','Pettersen')

Upvotes: 5

Andy Lester
Andy Lester

Reputation: 93715

Negate your condition with NOT.

select * from persons
where NOT (LastName IN ('Hansen','Pettersen'));

Upvotes: 2

manji
manji

Reputation: 47978

Simply NOT IN:

SELECT * FROM Persons
Where LastName NOT IN (...)

Upvotes: 4

Alex K.
Alex K.

Reputation: 175866

You can negate the IN with NOT:

SELECT * FROM Persons
WHERE LastName NOT IN ('hansen', 'Pettersen')

Upvotes: 4

Conrad Frix
Conrad Frix

Reputation: 52675

WHERE lastname NOT IN ('Hansen', 'Pettersen')

see the section "The IN and NOT IN operators" in SQL As Understood By SQLite

Upvotes: 23

Related Questions