Operator precedences are shown in the following list, from highest precedence to the lowest. Operators that are shown together on a line have the same precedence.
INTERVAL BINARY, COLLATE ! - (unary minus), ~ (unary bit inversion) ^ *, /, DIV, %, MOD -, + <<, >> & | =, <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN BETWEEN, CASE, WHEN, THEN, ELSE NOT &&, AND XOR ||, OR :=
The ||
operator has
a precedence between
^
and the
unary operators if the
PIPES_AS_CONCAT
SQL mode is
enabled.
The precedence shown for NOT
is as
of MySQL 5.0.2. For earlier versions, or from 5.0.2 on if the
HIGH_NOT_PRECEDENCE
SQL mode
is enabled, the precedence of NOT
is the same as that of the
!
operator. See
Section 5.1.7, “Server SQL Modes”.
The precedence of operators determines the order of evaluation of terms in an expression. To override this order and group terms explicitly, use parentheses. For example:
mysql>SELECT 1+2*3;
-> 7 mysql>SELECT (1+2)*3;
-> 9
User Comments
Also note that if you are using both math and logical operators you should use both logical and mathematical operators in their order of precedence for the command to function correctly.
Add your own comment.