In keyword in MS SQL Server


SQL Server IN keyword is use to extend the filter on select statement.

In keyword we use when we need select data from multiple options.
We have to provide the value in comma (,) separate format in IN keyword and SQL Sever check the data from given values.

Let consider below list of shopping items and we are going to apply IN keyword in this table.

select statement for In key word in sql server

SQL Server IN keyword example


Select table rows using IN keyword / statement

Select the product from Shopping table where dealer country from (in) USA, China and Japan.

Example

SELECT * FROM tblShoppingList
WHERE DealerCountry IN ( 'USA' , 'China' , 'Japan' )

Output

In keyword in MS SQL Server


SQL Server IN keyword example


Select table rows using NOT IN keyword / statement

Select the product from Shopping table where dealer country not from (not in) USA, China and Japan.

Example

SELECT * FROM tblShoppingList
WHERE DealerCountry NOT IN ( 'USA' , 'China' , 'Japan' )

Output

Not In keyword in MS SQL Server


Note : Use the single cote for string values IN clause and for number use the direct values no need to give the single cote values.
String Example : Country IN ('USA' ,'China','Japan')
Number Example : Class IN (10,12)