The logical operators (AND, OR, and NOT) evaluate logical expressions as TRUE, FALSE, or NULL.

Operator: expr AND expr

The following are the possible function return states:
If both expressions are TRUE the function returns to TRUE.
If one or both of the expressions are FALSE the function returns FALSE.
If one expression is FALSE and the other is NULL the function returns FALSE.
If both expressions are NULL the function returns NULL.
If one expression is true and the other is NULL the function returns NULL.
For example:

SELECT true AND true, false AND true, null AND false, null AND true, null AND null
|
-->  true, false, false, null, null

Operator: expr OR expr

The following are the possible function return states:
If one or both of the expressions are TRUE the function returns TRUE (including where the other expression is NULL).
If both expressions are FALSE the function returns FALSE.
If both expressions are NULL the function returns NULL.
If one of the expressions is NULL and the other is FALSE the function returns NULL.
For example:

SELECT true OR false, true OR null, false OR false, null OR null, false OR null
|
-->  true, true, false, null, null

Operator: NOT expr

The following are the possible function return states:
If the expression is TRUE the function returns FALSE.
If the expression is FALSE the function returns TRUE.
If the expression is NULL the function returns NULL.
For example:

SELECT 1 NOT in (2,3,4,5,6,7,8,9), NOT(1=1)
|
-->  true, false
Print Friendly, PDF & Email