SQL Operators
So
far,
we have used the =
operator for the obvious task
of verifying that two values in a WHERE
clause
equal one another. Other fairly basic operations include
<>
, >
,
<
, <=
, and
>=
. Note that MySQL allows you to use either
<>
or !=
for
“not equal.” Table 3-6 contains a full set of simple SQL operators.
Operator |
Context |
Description |
|
Arithmetic |
Addition |
|
Arithmetic |
Subtraction |
|
Arithmetic |
Multiplication |
|
Arithmetic |
Division |
|
Comparison |
Equal |
|
Comparison |
Not equal |
|
Comparison |
Less than |
|
Comparison |
Greater than |
|
Comparison |
Less than or equal to |
|
Comparison |
Greater than or equal to |
|
Logical |
And |
|
Logical |
Or |
|
Logical |
Negation |
MySQL operators have the following order of precedence:
BINARY
NOT !
-
(unary minus)* / %
+ -
<< >>
&
|
< <= > >= = <=> <> IN IS LIKE REGEXP RLIKE
BETWEEN
AND &&
OR ||
Get Managing & Using MySQL, 2nd 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.