1.and 只要一个条件不满足,算作不满足,where col1 = aa and col2 = bb
是当COL1 <> aa 的是时候,就不再判断Col2 是否等于bb了
where col1 = aa or col2 = bb
当COL1 = aa 的是时候,就不再判断Col2 是否等于bb
2.我说的是mssql,别的我没用过,应该是一样的

解决方案 »

  1.   

    你可以做以下实验: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 你会发现他没有去找表--说明微软已经做了优化!
      

  2.   

    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