MySQL follows operator precedence, it has the following list of operators, with the same precedence and on the same line -
INTERVAL BINARY, COLLATE ! - (unary minus), ~ (unary bit inversion) ^ *, /, DIV, %, MOD -, + <<, >> & | =, <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN BETWEEN, CASE, WHEN, THEN, ELSE NOT &&, AND XOR ||, OR :=
for expressions Operators of the same precedence are evaluated from left to right.
The following example shows operator precedence versus result set -
mysql> Select 5+3/2-2; +---------+ | 5+3/2-2 | +---------+ | 4.5000 | +---------+ 1 row in set (0.00 sec)
In the above calculation, MySQL calculates /(div) first because of its Priority is higher than (addition) or – (subtraction).
The above is the detailed content of How does MySQL operator precedence affect result sets?. For more information, please follow other related articles on the PHP Chinese website!