ITeye博客

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

cuityang · 2012-05-25 22:52 · oracle · Web前端 · Markdown

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。