1.oracle中联接(join)分为内联接(inner)和外联接(outer join),而外联接(outer join)又分为 左外联接(left outer join)和右外联接(right outer join)。 2. select * from TEST2; select * from TEST3; (1)笛卡尔乘积(Cartesian Product) select * from TEST2
1.oracle中联接(join)分为内联接(inner)和外联接(outer join),而外联接(outer join)又分为
左外联接(left outer join)和右外联接(right outer join)。
2.
select * from TEST2;
select * from TEST3;
(1)笛卡尔乘积(Cartesian Product)
select * from TEST2, TEST3;
结果:
(2)内联接(inner join)
select * from TEST2 inner join TEST3 on test3.c2 = test2.c2;
结果:
(3)外联接(outer join)--作用:由于显示悬浮元祖
2.1 右外联接(right outer join)
select * from TEST2 right outer join TEST3 on TEST2.C2 = TEST3.C2;--usage 1 select * from TEST2, TEST3 where TEST2.C2(+) = TEST3.C2;--usage 2
上述2条语句均表示右外联接
结果:
2.2 左外联接(left right join)
select * from TEST2 left outer join TEST3 on TEST2.C2 = TEST3.C2;--usage 1 select * from TEST2, TEST3 where TEST2.C2 =TEST3.C2(+);--usage 2
上述2条语句均表示左外联接
结果:
附录:数据库关于联接的概念
1.悬浮元素(dangling tuple):在一个联接中,若一个元组不能和另一个关系中的任何一个元组配对的话,该元组就成为悬浮元祖。
2.(1)笛卡尔乘积(2)积(3)交叉乘积 均表示同一个意思。
3.自然联接(natural join)
3.1.先做条件联接
3.2.对2个相同属性合并