SQL Logical Operator

Three logical operators are provided by SQL server to combine multiple search conditions. Those are OR, AND & NOT.

OR-returns the result when any of the specified search conditions are true.
AND- Returns the result when all the specified search conditions are true.
NOT- For a row to be selected the specified condition must be false.

In the WHERE clause the conditions can be combined using the logical operator.

Syntax:
SELECT column_name(s) FROM table_name WHERE conditional_expression {AND\OR}[NOT] conditional_expression
Where conditional_expression is any conditional expression that is combined with a logical operator.



The following SQL statement selects all publishers from the country “USA” AND the city "Washington", in the "publishers" table.

SELECT * FROM publishers WHERE country = 'USA' AND city = 'Washington'

SQL AND

The following SQL statement selects all publishers from the country “USA” or the city "Washington", in the "publishers" table.

SELECT * FROM publishers WHERE country = 'USA' OR city = 'Washington'

SQL AND

The following SQL statement selects all publishers from publishers table except from the country ‘USA’.

SELECT * FROM publishers WHERE NOT country = 'USA'

SQL NOT