Logical operators
Logical operators combine conditions. Their operands are boolean expressions or numbers: 0 is false, any other number is true, and NULL is unknown. The result is 1 (true), 0 (false) or NULL.
| Operator | Result |
|---|---|
AND, && |
True if both operands are true. |
OR |
True if at least one operand is true. |
XOR |
True if exactly one operand is true; NULL if either operand is NULL. |
NOT, ! |
True if the operand is false, and false if it is true. |
|| means OR only when the pipes_as_concat parameter is no. By default it is yes, and || concatenates strings: 'a' || 'b' returns 'ab'.
Truth table
Section titled “Truth table”| a | b | A AND b | A OR b | A XOR b | NOT a |
|---|---|---|---|---|---|
| TRUE | TRUE | TRUE | TRUE | FALSE | FALSE |
| TRUE | FALSE | FALSE | TRUE | TRUE | FALSE |
| TRUE | NULL | NULL | TRUE | NULL | FALSE |
| FALSE | TRUE | FALSE | TRUE | TRUE | TRUE |
| FALSE | FALSE | FALSE | FALSE | FALSE | TRUE |
| FALSE | NULL | FALSE | NULL | NULL | TRUE |
| NULL | NULL | NULL | NULL | NULL | NULL |
SELECT (1 AND NULL), (0 AND NULL), (1 OR NULL), (0 OR NULL), (1 XOR 0), (NOT NULL), (2 AND 3)FROM db_root;| (1 AND NULL) | (0 AND NULL) | (1 OR NULL) | (0 OR NULL) | (1 XOR 0) | (NOT NULL) | (2 AND 3) |
|---|---|---|---|---|---|---|
| NULL | 0 | 1 | NULL | 1 | NULL | 1 |
In a WHERE clause, a row is returned only when the condition is true; rows for which it is false or NULL are left out.