left join on and与left join on where的区别 分享
inner jion没这个特殊性,则条件放在on中和where中,返回的结果集是相同的。
tab1:
id psize
1 10
2 20
3 30
表2 tab2:
psize name
10 AAA
20 BBB
20 CCC
oracle 中
select * from tab1 left join tab2 on tab1.psize = tab2.psize and tab1.psize='10'
这里的先查询tab1.psize的结果,然后条件不为真也会返回左表中的记录
1 10 10 AAA
2 20
3 30
即使时0,也会
select * from tab1 left join tab2 on tab1.psize = tab2.psize and tab1.psize='0'
同:select * from tab1 left join tab2 on (tab1.psize = tab2.psize and tab1.psize='0')
ID PSIZE PSIZE NAME
1 10
2 20
3 30
mysql中
select * from tab1 left join tab2 on tab1.psize = tab2.psize and tab1.psize='10'
后面一个条件是不执行的
2
select * from tab1 left join tab2 on (tab1.psize = tab2.psize) where tab2.name='AAA'
先执行where前面的语句放入中间表
select * from tab1 left join tab2 on (tab1.psize = tab2.psize)
1 10 10 AAA
2 20 20 BBB
2 20 20 CCC
3 30
然后执行where语句
1 10 10 AAA
left join on and与left join on where的区别
原创mb636514f3a19f5 ©著作权
©著作权归作者所有:来自51CTO博客作者mb636514f3a19f5的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:cookie 的使用方式
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
left join 后用 on 还是 where?
sql语法
SQL sql 结果集 -
left join on与where的区别
left join on and与whereinner join on 与where
on where left join inner -
left join right join区别
参考https://zhuanlan.zhihu.com/p/52344330
spring 参数 mysql 数据库 -
LEFT OUTER JOIN = LEFT JOIN, INNERJOIN= WHERE=Join
在以下的帖子中说 INNERJOIN= WHERE=Join ://baike.360.cn/42
html 数据库 java hive javascript