How exactly does using OR in a MySQL statement differ with/without parentheses?

后端 未结 8 1606
难免孤独
难免孤独 2020-11-29 08:20

I have this query:

SELECT * FROM (`users`) WHERE `date_next_payment` <= \'2011-02-02\' 
    AND `status` = \'active\' OR `status` = \'past due\'
         


        
8条回答
  •  庸人自扰
    2020-11-29 09:13

    The MySQL manual has a page on operator precedence. It shows that AND has a higher precedence. So p1 AND p2 OR p3 is interpreted as (p1 AND p2) OR p3. A truth table will easily convince you that this is different from p1 AND (p2 OR p3).

提交回复
热议问题