O'Reilly logo

Managing & Using MySQL, 2nd Edition by Hugh E. Williams, Randy Yarger, George Reese, Tim King

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Table 3-6. The simple SQL operators supported by MySQL

Operator

Context

Description

+

Arithmetic

Addition

-

Arithmetic

Subtraction

*

Arithmetic

Multiplication

/

Arithmetic

Division

=

Comparison

Equal

<> or !=

Comparison

Not equal

<

Comparison

Less than

>

Comparison

Greater than

<=

Comparison

Less than or equal to

>=

Comparison

Greater than or equal to

AND

Logical

And

OR

Logical

Or

NOT

Logical

Negation

MySQL operators have the following order of precedence:

  1. BINARY

  2. NOT !

  3. - (unary minus)

  4. * / %

  5. + -

  6. << >>

  7. &

  8. |

  9. < <= > >= = <=> <> IN IS LIKE REGEXP RLIKE

  10. BETWEEN

  11. AND &&

  12. OR ||

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required