简单来说:
SQL join 用于把来自两个或多个表的行结合起来。基于这些表之间的共同字段。
可以看下图图例表示的话 LEFT JOIN、RIGHT JOIN、INNER JOIN、OUTER JOIN 相关的 7 种用法
常见的 JOIN 类型:SQL INNER JOIN(简单的 JOIN)。 SQL INNER JOIN 从多个表中返回满足 JOIN 条件的所有行。
select * from TableA a inner join TableB b on a.id =b.aid
select * from TableA a left join TableB b on a.id =b.aid
select * from TableA a right join TableB b on a.id =b.aid
select * from TableA a left join TableB b on a.id =b.aid
union
select * from TableA a right join TableB b on a.id =b.aid
select * from TableA a left join TableB b where b.aid is null
union
select * from TableA a right join TableB b where a.id is null