京东面试官问:LEFT JOIN 关联表中用 ON 还是 WHERE 跟条件有什么区别?
JAVA葵花宝典
共 1709字,需浏览 4分钟
·
2021-05-06 16:57
之前有码友去京东面试,被问到 LEFT JOIN 关联表中用 ON 还是 WHERE 跟条件有什么区别,很快就答出来了,可是追问什么原因造成这一情况的,一时没回答上来。
运行sql :
select * from student s left join class c on s.classId=c.id order by s.id
运行sql :
select * from student s left join class c on s.classId=c.id and s.name="张三" order by s.id
运行sql :
select * from student s left join class c on s.classId=c.id and c.name="三年级三班" order by s.id
id | size |
1 | 10 |
2 | 20 |
3 | 30 |
size | name
|
10 | AAA |
20 | BBB |
20 | CCC |
1、select * form tab1 left join tab2 on (tab1.size = tab2.size) where tab2.name='AAA'
2、select * form tab1 left join tab2 on (tab1.size = tab2.size and tab2.name='AAA')
|
|
作者:jcpp9527
blog.csdn.net/wqc19920906/article/details/79785424
更多精彩文章请关注
评论