#######################一个SQL问题where a='A' and b='B' or c='C' 和where a='A' and (b='B' or c='C')结果一样吗?
where a='A' and b='B' or c='C'
和
where a='A' and (b='B' or c='C')
查询结果有什么不一样吗?为什么?
非常感谢!
和
where a='A' and (b='B' or c='C')
查询结果有什么不一样吗?为什么?
非常感谢!
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 selectedLOVE2008>为什么自己不试一下那
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')
自己检查一下结果集不就知道了么
where a='A' and (b='B' or c='C')
如果有c='C'的记录就不一样,反之结果一样
假设结果中有满足c='C'的记录,那么第一个查询出来的是所有c='C'的记录,不管a和b
而第二个查询出来的是c='C'与a='A'的交集,这就是不同
假设记录中没有满足c='C'的记录那么两个写法得到的结果一样
不过,真对不起,一时匆忙,写错了。而且我也自己试过了,只是不太确定,并想寻求理论依据,呵呵
其实,我想问的是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'的纪录?
非常感谢。
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'的纪录?正确
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'任意成立都可以)