Reputation: 7895
I know its recomended to use parenthesis to separate and
,or
statements.but I'm wondering how mysql engine does render statements without parenthesis.lets say we have this statement:
select * from users where A and B or C and D;
how would it be with parenthesis?
Upvotes: 1
Views: 961
Reputation: 2783
It is like in math expressions:
AND is like a PRODUCT
OR is like a SUM
so AND are executed before OR, unless differently indicated through parenthesis, like in math again.
Upvotes: 4
Reputation: 2436
AND has higher precedence than OR.
Priority of AND and OR operator in Mysql select query
Upvotes: 1
Reputation: 6065
AND has higher priority than OR.
select * from users where (A and B) or (C and D);
Refer to: http://dev.mysql.com/doc/refman/5.7/en/operator-precedence.html
Upvotes: 4