Updated on 2026-11-06 GMT+08:00

Logical Operators

Commonly used logical operators include AND, OR, and NOT. Their operation results have three possible values: TRUE, FALSE, and NULL, where NULL represents unknown. The precedence order is: NOT > AND > OR.

For operation rules, see Table 1, where A and B in the table represent logical expressions.

Table 1 Logical operators

Operator

Result Type

Description

A AND B

BOOLEAN

Returns TRUE if both A and B are TRUE. Returns FALSE if either A or B is FALSE. Otherwise, returns NULL.

A OR B

BOOLEAN

Returns TRUE if either A or B is TRUE. Otherwise returns FALSE. Returns NULL if A or B is NULL. Returns TRUE if one is TRUE and the other is NULL.

NOT A

BOOLEAN

Returns TRUE if A is FALSE. Returns NULL if A is NULL. Otherwise returns FALSE.

! A

BOOLEAN

Same as NOT A.

A IN (val1, val2, ...)

BOOLEAN

Returns TRUE if A equals any value in (val1, val2, ...). Otherwise returns FALSE.

A NOT IN (val1, val2, ...)

BOOLEAN

Returns TRUE if A does not equal any value in (val1, val2, ...). Otherwise returns FALSE.

EXISTS (subquery)

BOOLEAN

Returns TRUE if the subquery returns at least one row. Otherwise returns FALSE.

NOT EXISTS (subquery)

BOOLEAN

Returns TRUE if the subquery returns no rows. Otherwise returns FALSE.