Instagram
youtube
Facebook
Twitter

MS SQL Server IN Operator

MS SQL Server IN Operator

  • IN is used to replace or avoid multiple arguments combined with an OR in for SELECT, UPDATE or DELETE Statements.
  • Syntax:
Expression IN(value1, value2,....value_n);

Example:

SELECT * FROM [University].[dbo].[Student] WHERE Name IN('Ravi','Savi');

or

SELECT * FROM [University].[dbo].[Student] WHERE Name='Ravi' OR Name='Savi';
Id Name Branch CGPA
EN19CS301254 Ravi CSE 9.86
EN19CS301246 Savi CSE 9.23

 

Example:

SELECT * FROM [University].[dbo].[Student] WHERE Age IN(18,19,20);

or

SELECT * FROM [University].[dbo].[Student] WHERE Age=18 OR Age=19 OR Age=20);
Id Name Branch CGPA Age
EN19CS301254 Ravi CSE 9.86 19 
EN19CS301246 Savi CSE 9.23 18
EN19CS301248 Aayush CSE 7.25 20
EN19CS301258 Kavi CSE 7.50 19

IN with NOT Operator

Example:

SELECT * FROM [University].[dbo].[Student] WHERE Name NOT IN('Ravi','Savi');

or

SELECT * FROM [University].[dbo].[Student] WHERE Name<>'Ravi' AND Name<>'Savi';
Id Name Branch CGPA
EN19CS301248 Aayush CSE 7.25
EN19CS301258 Kavi CSE 7.50