举例说明 假设您有两个表,每个表只有一个列,表数据如下 A B- -1 32 43 54 6
注意,(1,2)是A表唯一的,(3,4)是公共的,并且(5,6)是B表独有的
内连接
内连接是A表的所有行交上B表的所有行得出的结果集
select * from a INNER JOIN b on a.a = b.b;select a.*, b.* from a,b where a.a = b.b;a | b–+–3 | 34 | 4 左外连接
左外连接是A表的所有行匹配上B表得出的结果集
select * from a LEFT OUTER JOIN b on a.a = b.b;select a.*, b.* from a,b where a.a = b.b(+);a | b–+—–1 | null2 | null3 | 34 | 4 右外连接
右外连接是B表的所有行匹配上A表得出的结果集
select * from a RIGHT OUTER JOIN b on a.a = b.b;select a.*, b.* from a,b where a.a(+) = b.b;a | 香港vps b—–+—-3 | 34 | 4null | 5null | 6 全连接
全连接是A表的所有行并上B表的所有行得出的结果集
select * from a FULL OUTER JOIN b on a.a = b.b; a | b—–+—– 1 | null 2 | null 3 | 3 4 | 4null | 6null | 5
?
16282224