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 Id EmpName Age Department
1 Ankur 20 Sales
2 David 25 Sales
3 John 22 HR
4 James 24 Production
5 Mohan 26 HR

 
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 Id EmpName Age Department
1 Ankur 20 Sales
2 David 25 Sales
3 John 22 HR
5 Mohan 26 HR

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.