The reason is that now you are dealing with three-valued logic .
- for the AND (be it and or &) operator, the result of the expression can be determined in the first match for FALSE.
- for the OR operator (be it | or ||), the result of the expression can be determined in the first match for TRUE.
- for any logical operation that has the leftmost operand of NULL, will return NULL.
So the tables you have given are incomplete: you need more entries to find out what happens when there are 8 possible input combinations (nine if you consider the null operator null
combination).
and
X | Y | X & Y --------------------------- true null null null true null false null false null false null true false false true true true false true false false false false
OR
X | Y | X | Y --------------------------- true null true null true null false null null null false null true false true true true true false true true false false false
Using your friends
analogy, you can say that for three-valued logic, And stands for FALSE and NULL as the result, while OR supports TRUE and NULL.
source share