sql中join与left-join图解区别

t1表内容如下:

t2表内容如下:

下面来简述join和left join/right join的区别:

inner join

select * from t1 inner join t2 on t1.id = t2.id;

公共部分的数据才会被查询出来;

left join

select * from t1 left join t2 on t1.id = t2.id;

sql中join与left-join图解区别_第1张图片

查询出来的结果和前表记录数一样多;

right join

select * from t1 right join t2 on t1.id = t2.id;

能转化为

select * from t2 left join t1 on t1.id = t2.id;

你可能感兴趣的:(sql中join与left-join图解区别)