SQL Server Tutorial
SQL Server supports logical operators such as OR, AND and NOT.
Logical operators can be used in the WHERE clause.
SELECT column_name1[, column_name2, ....] FROM table_name WHERE [ NOT ] conditional_expression [ AND | OR ] [ NOT ] conditional_expression
Let us consider the example 'Employee' database table.
SELECT * FROM Employee WHERE Country = 'US' OR City = 'Bangalore'Output:
SELECT * FROM Employee WHERE DeptId=1 AND Country = 'US'Output:
SELECT * FROM Employee WHERE NOT Country = 'US'Output:
If Multiple logical operators are used in single query, processing operation takes place based on precedence of logical operators.
Precedence level of logical operators in an expression is NOT, AND, and OR. precedence of logical operators can be changed using parentheses.
SELECT * FROM Employee WHERE (NOT (Country = 'US' AND City = 'Bangalore'))
SELECT * FROM Employee WHERE (NOT (Country = 'US' AND City = 'Bangalore')) AND NOT (Country = 'INDIA')Output:
SQL Server Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page