SQL:Join

来自WHY42
Riguz留言 | 贡献2023年10月12日 (四) 02:32的版本 (Created page with "=Example= <syntaxhighlight lang="bash"> A B - - 1 3 2 4 3 5 4 6 </syntaxhighlight> ==Inner Join== <syntaxhighlight lang="bash"> 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 | 3 4 | 4 </syntaxhighlight> ==Left Join== <syntaxhighlight lang="bash"> 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 | null 2 | null 3 | 3 4 | 4 </syntax...")
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

Example

A    B
-    -
1    3
2    4
3    5
4    6

Inner Join

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 | 3
4 | 4

Left Join

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 | null
2 | null
3 |    3
4 |    4

Right Join

select * from a RIGHT OUTER JOIN b on a.a = b.b;
select a.*, b.*  from a,b where a.a(+) = b.b;

a    |  b
-----+----
3    |  3
4    |  4
null |  5
null |  6

Full Join

select * from a FULL OUTER JOIN b on a.a = b.b;

 a   |  b
-----+-----
   1 | null
   2 | null
   3 |    3
   4 |    4
null |    6
null |    5