读书人

请教这两个语句有区别吗

发布时间: 2012-02-11 09:51:34 作者: rapoo

请问这两个语句有区别吗
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 '

如果没有区别,执行效率上那个更好啊
谢谢

[解决办法]
Create Table A
(IDInt)
Create Table B
(IDInt,
DateVarchar(10))
GO
Insert A Select 1
Union All Select 2
Union All Select 3

Insert 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
2

id
1
2
3
*/

读书人网 >SQL Server

热点推荐