The NOT IN operator checks a value within a set of values, and retrieve the rows from the table which are NOT matching. This is opposite of SQL IN operator.
SQL NOT IN Syntax
[Expression] NOT IN (value1,value2,value3…..);
Example:
Get the list from the Books table where the AUTHORSLASTNAME is not ‘kalka’ , ‘MEYER’ , ‘AUSTEN’.
Query:
SELECT TITLE,AUTHORFIRSTNAME,AUTHORLASTNAME FROM BOOKS
WHERE AUTHORLASTNAME NOT IN (‘kalka’,’MEYER’,’AUSTEN’);
Output
TITLE | AUTHORFIRSTNAME | AUTHORLASTNAME |
---|---|---|
Animal Farm | George | Orwell |
Madhushala | Girish | Karnad |
Historica | Herodotus | Herodotus |
MOON CALLED | PATRICIA | BRIGS |