First 重点 ----> 能用括号的加上括号 防止出错!
优先级是=====>() > not > and > or
select * from table where …
where后边的判断但凡出现了or,为了方便理解 可以看做没有…
借用另外一个博主的sql 解释一下
1、select 1 from dual where 1=1 and 2=2 or 3=3 and 4=5 (这里考下大家,是否需要加括号呢?)
2、select 1 from dual where 1=1 or 2=2 and 3=4 (这里考下大家,是否需要加括号呢?)
方便理解用括号拆解一下
1、select 1 from dual where (1=1 and 2=2) or (3=3 and 4=5)
2、select 1 from dual where 1=1 or (2=2 and 3=4)