Skip to main content

Comparisons

Comparison Operators

The table below shows the standard comparison operators. Whenever either of the input arguments is NULL, the output of the comparison is NULL.

OperatorDescriptionExampleResult
<less than2 < 3TRUE
>greater than2 > 3FALSE
<=less than or equal to2 <= 3TRUE
>=greater than or equal to4 >= NULLNULL
=equalNULL = NULLNULL
<> or !=not equal2 <> 2FALSE

The table below shows the standard distinction operators. These operators treat NULL values as equal.

OperatorDescriptionExampleResult
IS DISTINCT FROMequal, including NULL2 IS DISTINCT FROM NULLTRUE
IS NOT DISTINCT FROMnot equal, including NULLNULL IS NOT DISTINCT FROM NULLTRUE

BETWEEN and IS (NOT) NULL

Besides the standard comparison operators there are also the BETWEEN and IS (NOT) NULL operators. These behave much like operators, but have special syntax mandated by the SQL standard. They are shown in the table below.
Note that BETWEEN and NOT BETWEEN are only equivalent to the examples below in the cases where both a, x and y are of the same type, as BETWEEN will cast all of its inputs to the same type.

PredicateDescription
a BETWEEN x AND yequivalent to a >= x AND a <= y
a NOT BETWEEN x AND yequivalent to a < x OR a > y
expression IS NULLTRUE if expression is NULL, FALSE otherwise
expression ISNULLalias for IS NULL (non-standard)
expression IS NOT NULLFALSE if expression is NULL, TRUE otherwise
expression NOTNULLalias for IS NOT NULL (non-standard)