准备两张表:
table1
1 zs 175
2 ls 170
3 ww 140
4 lz 190
table2
1 zs 60
2 qq 50
当leftjoin后的条件,写在on后面时:
select
*
from table1 a
left join table2 b
on a.id=b.id
and a.name=b.name
输出结果:
1 zs 175 1 zs 60
2 ls 170 null null null
3 ww 140 null null null
4 lz 190 null null null
当leftjoin后的条件,写在where后面时:
select
*
from table1 a
left join table2 b
on a.id=b.id
where a.name=b.name
输出结果:
1 zs 175 1 zs 60
本文探讨了在SQL查询中,LEFT JOIN 后的条件放在ON子句和WHERE子句的不同位置如何影响输出结果。通过两个具体示例展示了当条件在ON后时所有匹配和不匹配的记录都会显示,而在WHERE后时仅显示匹配的记录。
478

被折叠的 条评论
为什么被折叠?



