7种SQL JOINS的实现
下面的图片都是是两种表的连接查询图,它们插叙的结果各不相同。图中红色部分代表最后查询的结果。
内连接
select * from tableA A inner join tableB B on A.key=b.key
左外连接
select * from tableA A left join tableB B on A.key=B.key
select * from tableA A left join tableB B on A.key=B.key where B.key is null
右外连接
select * from tableA A right join tableB B on A.key=B.key
select * from tableA A right join tableB B on A.key=B.key where A.key is null
全连接
select * from tableA A full outer join tableB B on A.key=B.key
全外连接
select * from tableA A full outer join tableB B on A.key=B.key where A.key is null or B.key is null