废话不多说,直接上图秒懂。
t1表的结构与数据如下:
t2表的结构与数据如下:
inner join
select * from t1 inner join t2 on t1.id = t2.id;
inner join会把公共部分的数据查询出来:
left join
select * from t1 left join t2 on t1.id = t2.id;
left join查询出来的结果和前表记录数一样多,后表如果没有对应记录,则列为空:
right join
right join能转化为left join,例如:
select * from t1 right join t2 on t1.id = t2.id;
能转化为
select * from t2 left join t1 on t1.id = t2.id;
只是前表发生了变化而已。