Using IN in SQL Server

IN operator we use when we Determines whether a specified value matches any value in a sub query or a list. The IN operator allows you to specify multiple values in a WHERE clause.it also helps reduce the need to use multiple OR conditions.

Summery

SELECT col_name(s)
FROM tbl_name
WHERE col_name1 IN (val1,val2,…)

Example

Suppose you have a table ‘tbl_employee’
Table name: tbl_Employee

Employee IdEmpNameAgeDepartment
1Ankur20Sales
2David25Sales
3John22HR
4James24Production
5Mohan26HR

 
Now we want to select all employee details from HR and Sales Department then we use following query:

SELECT * FROM tbl_Employee WHERE Department IN ('Sales','HR')

 

Employee IdEmpNameAgeDepartment
1Ankur20Sales
2David25Sales
3John22HR
5Mohan26HR

Author: Ankur

Have worked primarily in the domain of Calling, CRM and direct advertisers services. My technological forte is Microsoft Technologies especially Dot Net (Visual Studio 2003, 2005, 2008, 2010 and 2012) and Microsoft SQL Server 2000,2005 and 2008 R2. My Area of Expertise is in C#. Net, VB.Net, MS-SQL Server, ASP. Net, Silverlight, HTML, XML, Crystal Report, Active Reports, Infragistics, Component Art, ComponeOne, Lead Tools etc.