SQL Server Tutorial
List operators are used to retrieve the data using the condition specified with list of values.
SQL Server supports list operators such as IN and NOT IN.
List operators can be used in the WHERE clause.
SELECT column_name1[, column_name2, ....] FROM table_name WHERE expression1 [IN| NOT NOT] (value-1, value-2,...value-n)here expression can be constant, variable, return value of function, column value or any combination of constant, variable, function or column value.
Let us consider the example 'Employee' database table.
IN operator is used to specify the condition based on list of values in WHERE clasue.
To get rows based on salary either 6000 or 8000 in a Employee table.
SELECT Name, DeptId, City, Email, Salary FROM Employee WHERE Salary IN (6000, 8000)Output:
To get rows based on DeptId either 1 or 2.
SELECT Name, DeptId, City, Email, Salary FROM Employee WHERE DeptId IN (1, 3)Output:
NOT IN operator is used to specify the condition based on list of values in WHERE clasue.
To get rows based on salary except 6000 and 8000 in a Employee table.
SELECT Name, DeptId, City, Email, Salary FROM Employee WHERE Salary NOT IN (6000, 8000)Output:
To get rows based on DeptId except 1 and 2.
SELECT Name, DeptId, City, Email, Salary FROM Employee WHERE DeptId NOT IN (1, 3)Output:
SQL Server Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page