Comparison Operators
Comparison operators compare values
and return 1 if the comparison is true and 0 otherwise. Except for
the <==> operator, NULL
values cause a comparison operator to evaluate to
NULL.
-
<>or!= Match rows if the two values are not equal.
-
<= Match rows if the left value is less than or equal to the right value.
-
< Match rows if the left value is less than the right value.
-
>= Match rows if the left value is greater than or equal to the right value.
-
> Match rows if the left value is greater than the right value.
-
valueBETWEENvalue1ANDvalue2 Match rows if
valueis betweenvalue1andvalue2, or equal to one of them.-
valueIN(value1,value2,...) Match rows if
valueis among the values listed.-
valueNOT IN(value1, value2,...) Match rows if
valueis not among the values listed.-
value1LIKEvalue2 Compares
value1tovalue2and matches the rows if they match. The righthand value can contain the wildcard'%', which matches any number of characters (including 0), and'_', which matches exactly one character. This is probably the single most used comparison in SQL. Its most common use is comparing a field value with a literal containing a wildcard (e.g.,SELECTnameFROMpeopleWHEREnameLIKE'B%').-
value1NOT LIKEvalue2 Compares
value1tovalue2and matches the rows if they differ. This is identical toNOT (value1 LIKE value2).-
value1REGEXP/RLIKEvalue2 Compares
value1tovalue2using the extended regular expression syntax and matches the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access