码迷,mamicode.com
首页 > 其他好文 > 详细

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

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

标签:left join   round   and   span   tab   条件   table   返回   bsp   

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 的区别

标签:left join   round   and   span   tab   条件   table   返回   bsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!