我不明白为什么右外连接(下面的例子)没有像左外连接那样给出表的完整数据集;因为外连接总是保留对应表的行。
创建表
create table join_test
(id number unique not null, name varchar2(10), department varchar2(10));
填充表
select * from join_test;
ID NAME DEPARTMENT 1 stelios sa 2 andros sa 3 stav ba 4 mary ba 5 antonia la 6 lambros ka
内部联接
select j1.name, j1.department
from join_test j1 join join_test j2
on(j1.department=j2.department and j1.name<>j2.name);
NAME DEPARTMENT andros sa steliso sa mary ba stav ba
左外连接
select j1.name, j1.department
from join_test j1 left join join_test j2
on(j1.department=j2.department and j1.name<>j2.name)
NAME DEPARTMENT andros sa steliso sa mary ba stav ba antonia la lambros ka
右外连接
select j1.name, j1.department
from join_test j1 right join join_test j2
on(j1.department=j2.department and j1.name<>j2.name)
NAME DEPARTMENT steliso sa andros sa stav ba mary ba
将选择列表更改为 j2
select j2.name, j2.department
from join_test j1 right join join_test j2
on(j1.department=j2.department and j1.name<>j2.name)
NAME DEPARTMENT andros sa steliso sa mary ba stav ba antonia la lambros ka