요즘 너무 글을 안올려서 간만에 포스팅합니다.
쌩뚱맞지만 갑자기 생각나서.. 급히 짜본 쿼리;;;
어려운 내용은 아니지만 기본기를 다진다는 차원에서 ^^
SELECT
T1.PK AS T1_PK,
T2.PK AS T2_PK,
T1.COL1,
T2.COL2
FROM
(
SELECT
*
FROM
(
SELECT '1' AS PK, 'A' AS COL1 FROM DUAL
UNION ALL
SELECT '2' AS PK, 'B' AS COL1 FROM DUAL
UNION ALL
SELECT '3' AS PK, 'C' AS COL1 FROM DUAL
UNION ALL
SELECT '5' AS PK, 'E' AS COL1 FROM DUAL
)
) T1
INNER JOIN
-- LEFT OUTER JOIN
-- RIGHT OUTER JOIN
(
SELECT
*
FROM
(
SELECT '1' AS PK, 'A' AS COL2 FROM DUAL
UNION ALL
SELECT '2' AS PK, 'B' AS COL2 FROM DUAL
UNION ALL
SELECT '3' AS PK, 'C' AS COL2 FROM DUAL
UNION ALL
SELECT '4' AS PK, 'D' AS COL2 FROM DUAL
)
) T2
ON T1.PK = T2.PK
결과
INNER JOIN
T1_PK|T2_PK|COL1|COL2
1 1 A A
2 2 B B
3 3 C C
LEFT OUTER JOIN
T1_PK|T2_PK|COL1|COL2
1 1 A A
2 2 B B
3 3 C C
5 E
RIGHT OUTER JOIN
T1_PK|T2_PK|COL1|COL2
1 1 A A
2 2 B B
3 3 C C
4 D
끝.
'SQL' 카테고리의 다른 글
[비공개] Oracle 대용량 insert (0) | 2017.06.29 |
---|---|
Oracle dynamic date 오라클 동적 시간 만들기 (0) | 2017.06.28 |
ORACLE WITH (0) | 2017.01.25 |
ms-sql 재귀쿼리 (0) | 2016.12.19 |
MySql에서 날짜 테이블 비슷한거 만들기 (0) | 2016.12.16 |