T-SQL Tutorial T-SQL Advanced Database Management T-SQL References

T-SQL - IN Keyword



The T-SQL (Transact-SQL) IN keyword is used to specify multiple values in a WHERE clause of T-SQL statement. It is a shorthand for multiple OR conditions.

Syntax

The syntax for using IN keyword in T-SQL (Transact-SQL) is given below:

SELECT column1, column2, column3, ...
FROM table_name
WHERE column_name IN (value1, value2, ...);

Example:

Consider a database containing a table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To select all records of the Employee table where City is London, Paris or Amsterdam, the query is given below.

    SELECT * FROM Employee
    WHERE City IN ('London', 'Paris', 'Amsterdam');
    

    This will produce the result as shown below:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    3JoParis272800
    4KimAmsterdam303100
  • Multiple values for the IN keyword can also be specified using SELECT statement.

    SELECT * FROM Employee
    WHERE City IN (SELECT City from Employee);
    

    This will produce the result as shown below:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800
    4KimAmsterdam303100
    5RameshNew Delhi283000
    6HuangBeijing282800

❮ T-SQL Keywords