左连接、右连接、内连接、外连接简单说明

例如有两个表:

test1:

test2:

内连接:(inner join on)返回两个表的交集。

例如:

select * from test1 a inner join test2 b on a.id=b.id;

结果:

外连接:返回两个表的并集。(在此就不做截图了)
 

左连接:(left join on)根据条件返回第一个表中存在的数据。

例如:

select * from test1 a left join test2 b on a.id=b.id;

结果:

右连接:(right join on)与左连接类似,返回第二个表中存在的数据。

例如:

select * from test1 a RIGHT join test2 b on a.id=b.id;

结果:

原文地址:https://www.cnblogs.com/0B0S/p/13708336.html