## Comparison Operators

 Operator Description < less than > greater than <= less than or equal to >= greater than or equal to = equal <> or != not equal

## Note

The != operator is converted to <> in the parser stage. It is not possible to implement != and <> operators that do different things.

Comparison operators are available for all relevant data types. All comparison operators are binary operators that return values of type boolean; expressions like 1 < 2 < 3 are not valid (because there is no < operator to compare a Boolean value with 3).

In addition to the comparison operators, the special BETWEEN construct is available:

`a BETWEEN x AND y`

is equivalent to

`a >= x AND a <= y`

Notice that BETWEEN treats the endpoint values as included in the range. NOT BETWEEN does the opposite comparison:

`a NOT BETWEEN x AND y`

is equivalent to

`a < x OR a > y`

BETWEEN SYMMETRIC is the same as BETWEEN except there is no requirement that the argument to the left of AND be less than or equal to the argument on the right. If it is not, those two arguments are automatically swapped, so that a nonempty range is always implied.

Ordinary comparison operators yield null (signifying “unknown”), not true or false, when either input is null. For example, 7 = NULL yields null, as does 7 <> NULL. When this behaviour is not suitable, use the IS [ NOT ] DISTINCT FROM constructs:

```a IS DISTINCT FROM b
a IS NOT DISTINCT FROM b```

For non-null inputs, IS DISTINCT FROM is the same as the <> operator. However, if both inputs are null it returns false, and if only one input is null it returns true. Similarly, IS NOT DISTINCT FROM is identical to = for non-null inputs, but it returns true when both inputs are null, and false when only one input is null. Thus, these constructs effectively act as though null were a normal data value, rather than “unknown”.

To check whether a value is or is not null, use the constructs:

```expression IS NULL
expression IS NOT NULL```

or the equivalent, but nonstandard, constructs:

```expression ISNULL
expression NOTNULL```

Boolean values can also be tested using the constructs

```expression IS TRUE
expression IS NOT TRUE
expression IS FALSE
expression IS NOT FALSE
expression IS UNKNOWN
expression IS NOT UNKNOWN```