Reputation: 39384
Which operator: /
or *
will have the higher priority in MySQL
?
Upvotes: 2
Views: 3240
Reputation: 34421
The answer is: it shouldn't matter. If you have an expression that you are not sure how it's evaluated, use parens. They're free.
Upvotes: 0
Reputation: 49134
Like most programming languages, mysql performs /
and *
(as well as DIV, % and MOD) from left to right, in the order they occur. For instance:
1 / 2 * 3 / 4 / 5 * 6
is equivalent to
((((1 / 2) * 3) / 4) / 5) * 6
See http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html for a complete list of operator precedence.
Upvotes: 4
Reputation: 25665
They have the same precedence, * is listed first, and MySQL will evaluate left to right.
http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html
My advice is use brackets () to make things clear.
It's always best to check, and that can be done very easily with MySQL:
mysql> SELECT 2*3/2, 2/3*2, 2*(3/2) ;
+--------+--------+---------+
| 2*3/2 | 2/3*2 | 2*(3/2) |
+--------+--------+---------+
| 3.0000 | 1.3333 | 3.0000 |
+--------+--------+---------+
1 row in set (0.00 sec)
Upvotes: 1
Reputation: 2222
The operators are prioritized as listed from the highest precedence to the lowest:
As per list, the comparison BINARY operator has precedence over the BETWEEN and ampersand (&) operators. Operators on the same line above have the same level of precedence, and are evaluated in the order of usage.
Source http://www.learn-mysql-tutorial.com/Expressions.cfm
Upvotes: 2
Reputation:
They are the same see http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html
Upvotes: 1
Reputation: 425823
/ or * will have the highest priority in mysql.
They're of same priority.
Upvotes: 0