Comparison Operators

You often want to look at values in relation to one another to find out which is “larger” or “smaller” or “lower” in the alphabet sort or “equal” to some other database value or to a constant. SQL provides a set of comparison operators for these purposes. In most dialects, the comparison operators are these:

OperatorMeaning
=equal to
>greater than
<less than
>=greater than or equal to
<=less than or equal to
< >not equal to

The operators are used in the syntax:

WHERE expression comparison_operator expression

An expression can be a plain column name or something more complex—a character string, a function or calculation (usually involving a column name), or any combination of these elements connected by arithmetic operators. When ...

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.