select a.col1 from a
left join b on a.id=b.id
where b.date='2007-1-1'
select a.col1 from a
left join b on a.id=b.id 
and b.date='2007-1-1'如果没有区别,执行效率上那个更好啊
谢谢

解决方案 »

  1.   

    如果是inner join,結果是一樣的,但是left join,結果很有可能是不一樣。
      

  2.   

    Create Table A
    (ID Int)
    Create Table B
    (ID Int,
     Date Varchar(10))
    GO
    Insert A Select 1
    Union All Select 2
    Union All Select 3Insert B Select 1, '2007-1-1'
    Union All Select 2, '2007-1-1'
    Union All Select 3, '2007-1-2'
    GO
    select a.id from a
    left join b on a.id=b.id
    where b.date='2007-1-1'
    select a.id from a
    left join b on a.id=b.id 
    and b.date='2007-1-1'GO
    Drop Table A, B
    --Result
    /*
    id
    1
    2id
    1
    2
    3
    */
      

  3.   

    Create Table A
    (ID Int)
    Create Table B
    (ID Int,
     Date Varchar(10))
    GO
    Insert A Select 1
    Union All Select 2
    Union All Select 3Insert B Select 1, '2007-1-1'
    Union All Select 2, '2007-1-1'
    Union All Select 3, '2007-1-2'
    GO
    select a.id from a
    inner join b on a.id=b.id
    where b.date='2007-1-1'
    select a.id from a
    inner join b on a.id=b.id 
    and b.date='2007-1-1'
    GO
    Drop Table A, B
    --Result
    /*
    id
    1
    2id
    1
    2
    */