alex
alex

Reputation: 7895

MYSQL AND & OR priority

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

Answers (3)

White Feather
White Feather

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

Hamza Zafeer
Hamza Zafeer

Reputation: 2436

AND has higher precedence than OR.

Priority of AND and OR operator in Mysql select query

Operator Precedence

Upvotes: 1

Dylan Su
Dylan Su

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

Related Questions