테이블 정의
create table proj (
task_id varchar2(3),
based_on varchar2(3),
task_in_charge varchar2(10)
);
데이터 삽입
insert into proj values('P01', '', 'KING');
insert into proj values('P02', 'P01', 'KOCHAR');
insert into proj values('P03', '', 'GREEN');
insert into proj values('P04', 'P03', 'SCOTT');
OUTER JOIN 쿼리 수행
SELECT p.task_id, p.based_on, d.task_in_charge
FROM proj p FULL OUTER JOIN proj d
ON (p.based_on = d.task_id);
SELECT p.task_id, p.based_on, d.task_in_charge
FROM proj p LEFT OUTER JOIN proj d
ON (p.based_on = d.task_id);
SELECT p.task_id, p.based_on, d.task_in_charge
FROM proj p RIGHT OUTER JOIN proj d
ON (p.based_on = d.task_id);
결과
TASK_ID | BASED_ON | TASK_IN_CHARGE |
---|---|---|
P02 | P01 | KING |
(null) | (null) | KOCHAR |
P04 | P03 | GREEN |
(null) | (null) | SCOTT |
P03 | (null) | (null) |
P01 | (null) | (null) |
TASK_ID | BASED_ON | TASK_IN_CHARGE |
---|---|---|
P02 | P01 | KING |
P04 | P03 | GREEN |
P03 | (null) | (null) |
P01 | (null) | (null) |
TASK_ID | BASED_ON | TASK_IN_CHARGE |
---|---|---|
P02 | P01 | KING |
P04 | P03 | GREEN |
(null) | (null) | KOCHAR |
(null) | (null) | SCOTT |