Skip to content

Logical expressions ​

Logical expressions combine conditions. SQL uses three truth values: true, false and unknown, represented by NULL.

Syntax ​

text
condition AND condition
condition OR condition
NOT condition

Operands are converted using SQL truth rules. A false operand makes AND false even when the other operand is NULL. A true operand makes OR true even when the other operand is NULL. NOT NULL remains NULL.

Truth table ​

A B A AND B A OR B
true true true true
true false false true
true NULL NULL true
false false false false
false NULL false NULL
NULL NULL NULL NULL

Examples ​

Combining missing and known conditions ​

sql
SELECT 1 AND NULL, 0 AND NULL, 1 OR NULL, NOT 0
FORMAT csv;
text
\N,0,1,1

Selecting matching rows ​

sql
CREATE TABLE orders (id INTEGER, paid Bool, amount INTEGER);
INSERT INTO orders VALUES (1, true, 100), (2, false, 200), (3, true, 40);
sql
SELECT id
FROM orders
WHERE paid AND amount >= 50
ORDER BY id
FORMAT csv;
text
1

A WHERE condition admits only true, so both false and NULL remove a row. Use IS NULL to test for a missing value, and conditional functions or coalesce to choose a fallback.