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.
Leave a Reply