MySQL offers three kinds of operators: arithmetic, comparison, and logical.
When your SQL contains complex expressions, the subexpressions are evaluated based on MySQL's rules of precedence. Of course, you may always override MySQL's rules of precedence by enclosing an expression in parentheses.
BINARY
NOT
^
- (unary minus)
* / %
+ -
<< >>
&
|
< <= > >= = <=> <> IN IS LIKE REGEXP
BETWEEN CASE
AND
OR XOR
Arithmetic operators perform basic arithmetic on two values.
Adds two numerical values
Subtracts two numerical values
Multiplies two numerical values
Divides two numerical values
Gives the modulo of two numerical values
Performs a bitwise OR on two integer values
Performs a bitwise exclusive OR on two integer values.
Performs a bitwise AND on two integer values
Performs a bitwise left shift on an integer value
Performs a bitwise right shift on an integer value
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.
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.
Match rows if value is between value1 and value2, or equal to one of them.
Match rows if value is among the values listed.
Match rows if value is not among the values listed.
Compares value1 to value2 and 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. Its most common use is comparing a field value with a literal containing a wildcard (e.g., SELECT name FROM people WHERE name LIKE 'B%').
Compares value1 to value2 and matches the rows if they differ. This is identical to NOT (value1 LIKE value2).
Compares value1 to value2 using the extended regular expression syntax and matches the rows if the two values match. The righthand value can contain full Unix regular expression wildcards and constructs (e.g., SELECT name FROM people WHERE name RLIKE '^B.*').
Compares value1 to value2 using the extended regular expression syntax and matches the rows if they differ. This is identical to NOT (value1 REXEXP value2).
Logical operators check the truth value of one or more expressions. In SQL terms, a logical operator checks whether its operands are 0, nonzero, or NULL. A 0 value means false, nonzero means true, and NULL means no value.
Performs a logical not (returns "1" if the value is 0, NULL if it is NULL, otherwise "0").
Performs a logical or (returns "1" if any of the arguments are nonzero and non-NULL, NULL if any are NULL; otherwise, returns "0").
Performs a logical exclusive or (returns "1" if one and only on argument is nonzero and non-NULL, NULL if any are NULL; otherwise. returns "0").
Performs a logical and (returns "0" if any of the arguments are 0, NULL if any are NULL; otherwise, returns "1").