Operator Precedence
The precedence is the order in which the SQL operators are evaluated.
The following list shows the SQL operator precedence. Operators that appear first in the list have a higher precedence. Operators which are listed together have the same precedence.
- INTERVAL
- BINARY, COLLATE
- !
- - (unary minus), ~ (unary bit inversion)
- || (string concatenation)
- ^
- *, /, DIV, %, MOD
- -, +
- >>, <<
- &
- |
- = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
- BETWEEN, CASE, WHEN, THEN, ELSE
- NOT
- &&, AND
- XOR
- || (bit or), OR
- = (assignment), :=
Functions precedence is always higher than operators precedence.
If the HIGH_NOT_PRECEDENCE
SQL_MODE is set, NOT
has the same precedence as !
.
The ||
operator's precedence, as well as its meaning, depends on the PIPES_AS_CONCAT
SQL_MODE flag: if it is on, ||
can be used to concatenate strings (like the CONCAT() function) and has a higher precedence.
The =
operator's precedence depends on the context - it is higher when =
is used as a comparison operator.
Parenthesis can be used to modify the operators precedence in an expression.