首页 > 其他 > 详细

left join on and 和left join on where 的区别

时间:2017-02-25 22:43:33      阅读:191      评论:0      收藏:0      [点我收藏+]

Table1: temp1

temp1Id Size
1           10
2           20
3           30

Table2: temp2

temp2Id Size Name
1            10   AAA
2            20   BBB
3            20   CCC

select * from dbo.temp1
left join dbo.temp2 on temp1.Size=temp2.Size

temp1Id Size temp2Id Size Name
1 10 1 10 AAA
2 20 2 20 BBB
2 20 3 20 CCC
3 30 NULL NULL NULL

select * from dbo.temp1
left join dbo.temp2 on temp1.Size=temp2.Size
where temp2.Name=‘AAA‘

temp1Id Size temp2Id Size Name
1 10 1 10 AAA

select * from dbo.temp1
left join dbo.temp2 on temp1.Size=temp2.Size
and temp2.Name=‘AAA‘

temp1Id Size temp2Id Size Name
1 10 1 10 AAA
2 20 NULL NULL NULL
3 30 NULL NULL NULL

总结:

on条件是在生成临时表时使用的条件,它不管on中的条件是否为真,都会返回左边表中的记录。 

 

left join on and 和left join on where 的区别

原文:http://www.cnblogs.com/zhenghuanhuan/p/6443092.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!