Search code examples
mysqloperator-precedence

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?


Solution

  • 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