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