Comparison predicates

<< Click to Display Table of Contents >>

Navigation:  Local SQL > Data Manipulation Language > Predicates >

Comparison predicates

Previous pageReturn to chapter overviewNext page
hmtoggle_plus1See also

Compare two values.

value1 < value2

 less than

value1 > value2

 greater than

value1 = value2

 equal to

value1 <> value2

 not equal to

value1 != value2

 not equal to (alternate syntax)

value1 >= value2

 greater than or equal to

value1 <= value2

 less than or equal to

Description

Use comparison predicates to compare two like values. Values compared can be: column values, literals, or calculations. The result of the comparison is a boolean value that is used in contexts like a WHERE clause to determine on a row-by-row basis whether a row meets the filtering criteria.

SELECT *

FROM Orders

WHERE (ItemsTotal >= 1000)

Comparisons must be between two values of the same or a compatible data type. If one value is of an incompatible data type, convert that value with the CAST function to a compatible data type.

The result of a comparison predicate can be modified by a logical operator, such as NOT.

SELECT *

FROM Orders

WHERE NOT (ItemsTotal >= 1000)

Note: comparison predicates can only be used in a WHERE or HAVING clause, or in the ON clause of a join; they cannot be used in the SELECT clause.