IN operator is used to reduce use of multiple OR conditions by specifying multiple values in WHERE clause.
Syntax of IN operator in SQL –
SELECT(ColumnName(s))
FROM <TableName>
WHERE<ColumnName>
IN (value1, value2…valueN) ;
Example of IN operator in SQL-
SELECT *
FROM Customers
WHERE City
IN (‘Berlin’,’London’,’Madrid’);
–It will select all the customers from any of the cities Berlin, London and Mandrid.
NOT IN
Syntax of NOT IN operator in SQL –
SELECT(ColumnName(s))
FROM <TableName>
WHERE<ColumnName>
NOT IN (value1, ..…valueN) ;
Example of NOT IN operator in SQL-
SELECT *
FROM Customers
WHERE City
NOT IN (‘Berlin’,’London’,’Madrid’);
–It will select all the customers that are not from any of the cities Berlin, London and Mandrid.
Note-
Northwind sample database is used for example.