曹耘豪的博客

MySQL理解and和or的优先级

1
2
3
4
5
6
7
8
SELECT * FROM TABLE t1 WHERE  条件1 AND 条件2 OR 条件3
-- 等价于
SELECT * FROM TABLE t1 WHERE ( 条件1 AND 条件2 ) OR 条件3


SELECT * FROM TABLE t1 WHERE 条件1 AND 条件2 OR 条件3 AND 条件4
-- 等价于
SELECT * FROM TABLE t1 WHERE ( 条件1 AND 条件2 ) OR ( 条件3 AND 条件4 )
   /