Using Comparison Operators in Expressions

From InterBase

Go Up to Understanding SQL Expressions


Comparison operators evaluate to a Boolean value: TRUE, FALSE, or UNKNOWN, based on a test for a specific relationship between a value to the left of the operator, and a value or range of values to the right of the operator. Values compared must evaluate to the same data type, unless the CAST()function is used to translate one data type to a different one for comparison. Values can be columns, constants, or calculated values.

The following table lists operators that can be used in statements, describes how they are used, and provides samples of their use:

Comparison operators
Operator Purpose

=

Equals

<

Less than

>

Greater than

>=

Greater than or equals

<=

Less than or equals

>, ~>, ^>

Not greater than

<, ~<, ^<

Not less than

<>, !=

Not equal to

Note:
Comparisons evaluate to UNKNOWN if a NULL value is encountered.

For more information about CAST(), see Using CAST( ) for Data Type Conversions.

InterBase also supports comparison operators that compare a value on the left of the operator to the results of a subquery to the right of the operator. The following table lists these operators, and describes how they are used:

InterBase comparison operators requiring subqueries
Operator Purpose

ALL

Determines if a value is equal to all values returned by a subquery.

ANY and SOME

Determines if a value is equal to any values returned by a subquery.

EXISTS

Determines if a value exists in at least one value returned by a subquery.

SINGULAR

Determines if a value exists in exactly one value returned by a subquery.

For more information about using subqueries, see Using Subqueries.

Topics

See Also:

Advance To: