当前位置: 代码迷 >> Sql Server >> 初学者求指点sql语句的有关问题
  详细解决方案

初学者求指点sql语句的有关问题

热度:8762   发布时间:2013-02-26 00:00:00.0
菜鸟求指点sql语句的问题
1.select * from file_table where (userid='zhangsan' or userid='ALL USER') and filename like '1k%' 
2.select * from file_table where userid='zhangsan' or userid='ALL USER' and filename like '1k%' 

在前面加括号的情况下,模糊查询能成功,在后面不加括号的情况下模糊查询就不能成功。
为什么?or的优先级大于所有的and吗
sql

------解决方案--------------------------------------------------------
(a=1 or b=2) and c=3
a=1 or b=2 and c=3  ======> a=1 or (b=2 and c=3)

所以兩句是不一樣的。

------解决方案--------------------------------------------------------
不加括号相当于
select * from file_table where userid='zhangsan' or 
(userid='ALL USER' and filename like '1k%')
显然与你的原意不符
  相关解决方案