#######################一个SQL问题where a='A' and b='B' or c='C' 和where a='A' and (b='B' or c='C')结果一样吗?

freekicker 2007-01-11 06:23:54
where a='A' and b='B' or c='C'

where a='A' and (b='B' or c='C')
查询结果有什么不一样吗?为什么?
非常感谢!
...全文
540 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
oliyio 2007-01-16
  • 打赏
  • 举报
回复
and>or优先级
starwang 2007-01-16
  • 打赏
  • 举报
回复
完全不一样
where a='A' and b='B' or c='C'
其实是(a='A' and b='B') or c='C' (a必须等于'A',b必须等于'B' 这两个条件必须同时满足)
怎么可能和 a='A' and (b='B' or c='C') 一样。
a='A' and (b='B' or c='C')(a必须等于'A',b='B' 或者 c='C'任意成立都可以)
qiyousyc 2007-01-15
  • 打赏
  • 举报
回复
where a='A' and b='B' or b='C'与where a='A' and (b='B' or b='C')的区别。
where a='A' and b='B' or b='C'的查询结果是不是所有b='C'的纪录以及满足a='A' and b='B'条件的纪录的合集?  正确
where a='A' and (b='B' or b='C')的查询结果是不是所有a='A'并且b是'B'或'C'的纪录?正确
freekicker 2007-01-15
  • 打赏
  • 举报
回复
怎么没人捧场阿,呵呵
swswssw 2007-01-13
  • 打赏
  • 举报
回复
无论是哪个字段都是一样道理
freekicker 2007-01-13
  • 打赏
  • 举报
回复
感谢大家捧场,呵呵
不过,真对不起,一时匆忙,写错了。而且我也自己试过了,只是不太确定,并想寻求理论依据,呵呵
其实,我想问的是where a='A' and b='B' or b='C'与where a='A' and (b='B' or b='C')的区别。
where a='A' and b='B' or b='C'的查询结果是不是所有b='C'的纪录以及满足a='A' and b='B'条件的纪录的合集?
where a='A' and (b='B' or b='C')的查询结果是不是所有a='A'并且b是'B'或'C'的纪录?
非常感谢。
swswssw 2007-01-11
  • 打赏
  • 举报
回复
where a='A' and b='B' or c='C'
where a='A' and (b='B' or c='C')
如果有c='C'的记录就不一样,反之结果一样
假设结果中有满足c='C'的记录,那么第一个查询出来的是所有c='C'的记录,不管a和b
而第二个查询出来的是c='C'与a='A'的交集,这就是不同
假设记录中没有满足c='C'的记录那么两个写法得到的结果一样


jsidiot 2007-01-11
  • 打赏
  • 举报
回复
1。不一样
2。三个条件 a='A' and b='B' or c='C'
a='A' and b='B'
||或者
c='C'
a='A' and (b='B' or c='C')
a='A' 并且 (b='B' 或者 c='C')
自己检查一下结果集不就知道了么
wangzk0206 2007-01-11
  • 打赏
  • 举报
回复
当然不一样了
LOVE2008>select * from test
2 where id=6 and name='zhouxuan' or addr=2;

ID NAME ADDR
---------- -------------------- ----------
7 zhouxuan 2
LOVE2008>select * from test
2 where id=6 and name='zhouxuan' and addr=2;

no rows selected

LOVE2008>

为什么自己不试一下那

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧