IN in SQL

HOW TO USE IN OPERATOR IN SQL?

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 I(โ€˜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.


Posted

in

Tags:

Comments

Leave a Reply