The WHERE
clause can be combined with AND, OR and NOT operators
The AND
and OR
operators are used to filter records based on more than one condition:
- The
AND
operator displays a record if all the conditions separated byAND
are TRUE. - The
OR
operator displays a record if any of the conditions separated byOR
is TRUE. - The
NOT
operator displays a record if the condition(s) is NOT TRUE.
SELECT column_name1, column_name2, ...
FROM [table_name]
WHERE condition_1 AND condition_2 ...
TRUE |
FALSE |
NULL |
|
TRUE |
TRUE |
FALSE |
NULL |
FALSE |
FALSE |
FALSE |
FALSE |
NULL |
NULL |
FALSE |
NULL |
SELECT BusinessEntityID,JobTitle,MaritalStatus FROM
HumanResources.Employee
WHERE
MaritalStatus = 'M'
AND JobTitle='Marketing Specialist'
SELECT column_name1, column_name2, ...
FROM [table_name]
WHERE condition_1 OR condition_2 ...
TRUE |
FALSE |
|
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
SELECT BusinessEntityID,JobTitle,MaritalStatus FROM
HumanResources.Employee
WHERE
MaritalStatus = 'M'
AND JobTitle='Marketing Specialist'
SELECT column_name1, column_name2, ...
FROM [table_name]
WHERE NOT CONDITION
SELECT BusinessEntityID,JobTitle,MaritalStatus FROM
HumanResources.Employee
WHERE
NOT MaritalStatus = 'M'