Opposite the IN statement in SQL

How can I do the opposite:

example

In other words, select all people whose last name is not Hansen or Pettersen.

+8
sql sqlite
source share
5 answers
WHERE lastname NOT IN ('Hansen', 'Pettersen') 

see the section "IN and NOT IN statements " in SQL as SQLite understands

+19
source share
 SELECT * FROM Persons WHERE LastName NOT IN ('Hansen','Pettersen') 
+5
source share

You can undo IN with NOT :

 SELECT * FROM Persons WHERE LastName NOT IN ('hansen', 'Pettersen') 
+4
source share

Just NOT IN :

 SELECT * FROM Persons Where LastName NOT IN (...) 
+4
source share

Cancel the condition with NOT.

 select * from persons where NOT (LastName IN ('Hansen','Pettersen')); 
+2
source share

All Articles