The MySQL official documentation provides operators with the following precedence:
Operator Precedences is shown in the following list, from highest precedence to the lowest. Operators that is shown together on a line has the the same precedence.
1 INTERVAL2 BINARY, COLLATE3!4-(unary minus), ~(unary bit inversion)5^6*,/, DIV,%, MOD7-, +8<<, >>9&Ten| One= (comparison), <=>, >=,;, <=, <, <>,! =, is, like, REGEXP, in A between, case, if, then, ELSE - not -And, && the XOR -OR, | | -= (Assignment),: =
The precedence of=
Depends on whether it is used as a comparison operator (=
) or as an assignment operator (=
). When used as a comparison operator, it had the same precedence as<=>
,>=
,>
,<=
,<
,<>
,!=
,IS
,LIKE
,REGEXP
, andIN
. When used as a assignment operator, it has the same precedence as:=
. Section 13.7.4.1, "SET Syntax for Variable assignment", and sections 9.4, "user-defined Variables", explain how MySQL deter Mines which interpretation of=
should apply.
For operators this occur at the same-precedence level within a expression, evaluation proceeds left-to-right, with the ex Ception that assignments the evaluate right to the left.
The meaning of some operators depends on the SQL mode:
By default, is ||
a logical OR
operator. PIPES_AS_CONCAT
with enabled, was ||
string concatenation, with a precedence between and the ^
unary operators.
By default, have !
a higher precedence than NOT
. HIGH_NOT_PRECEDENCE
with enabled, and has the !
NOT
same precedence.
See section 5.1.8, "Server SQL Modes".
The precedence of operators determines the order of evaluation of terms in an expression. To override the this order and the group terms explicitly, use parentheses. For example:
1 mysql> SELECT 1+2*3; 2 -73 mysql> SELECT (1+2); 4 9
[Js-mysql] Operator Precedence