1、
在WHERE条件中,请问
where col1 = aa and col2 = bb
是不是当COL1 <> aa 的是时候,就不再判断Col2 是否等于bb了?
同样在
where col1 = aa or col2 = bb
是不是当COL1 = aa 的是时候,就不再判断Col2 是否等于bb了?
2、上面的问题是否对每个DBMS都一样,如果不一样,那么分别是怎么样的情况,
如:MSSQL,ORACLE,DB2...是什么样的?
谢谢
...全文
1276打赏收藏
SQL的逻辑判断顺序
1、 在WHERE条件中,请问 where col1 = aa and col2 = bb 是不是当COL1 aa 的是时候,就不再判断Col2 是否等于bb了? 同样在 where col1 = aa or col2 = bb 是不是当COL1 = aa 的是时候,就不再判断Col2 是否等于bb了? 2、上面的问题是否对每个DBMS都一样,如果不一样,那么分别是怎么样的情况, 如:MSSQL,ORACLE,DB2...是什么样的? 谢谢
select A.*
from Table A,
(select B.col1,B.col2,...,B.coln from table B group by B.col1,B.col2,...,B.coln having count(1) > 1) C
where A.Col1 = C.Col1 and A.Col2 = C.Col2 and ....A.ColN = C.ColN
和
select A.*
from Table A
where
(select count(1)
from Table C
where A.Col1 = C.Col1 and A.Col2 = C.Col2 and ....A.ColN = C.ColN) > 1
哪个的效率高,更好的写法应该是什么?
帖子见
http://expert.csdn.net/Expert/topic/1508/1508012.xml?temp=.3553736
if 1=1 and exists(select 1 from pubs..jobs)
select 1
--按下F5后 ,按Ctrl+L 你会发现他去找了表
---------------------------------------------------
if 1=2 and exists(select 1 from pubs..jobs)
select 1
--按下F5后 ,按Ctrl+L 你会发现他没有去找表
1.and 只要一个条件不满足,算作不满足,where col1 = aa and col2 = bb
是当COL1 <> aa 的是时候,就不再判断Col2 是否等于bb了
where col1 = aa or col2 = bb
当COL1 = aa 的是时候,就不再判断Col2 是否等于bb
2.我说的是mssql,别的我没用过,应该是一样的