准备两张表:
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