SQL JOINS 조인

팡태(❁´◡`❁)·2022년 3월 22일
0

oracle/MySQL

목록 보기
8/13
post-thumbnail

● LEFT JOIN
A

SELECT <FIELD_LIST> 
FROM TABLEA A LEFT JOIN TABLEB B
ON A.PKEY = B.PKEY

A-B

SELECT <FIELD_LIST> 
FROM TABLEA A LEFT JOIN TABLEB B
ON A.PKEY = B.PKEY
WHERE B.PKEY IS NULL

● RIGHT JOIN
B

SELECT <FIELD_LIST> 
FROM TABLEA A RIGHT JOIN TABLEB B
ON A.PKEY = B.PKEY

B-A

SELECT <FIELD_LIST> 
FROM TABLEA A RIGHT JOIN TABLEB B
ON A.PKEY = B.PKEY
WHERE B.PKEY IS NULL

● OUTER JOIN
A∪B

SELECT <FIELD_LIST>
FROM TABLEA A FULL OUTER JOIN TABLEB B
ON A.PKEY = B.PKEY

A∪B-(A∩B): A∪B에서 A, B의 기본키 부분을 뺌

SELECT <FIELD_LIST>
FROM TABLEA A FULL OUTER JOIN TABLEB B
ON A.PKEY = B.PKEY
WHERE A.PKEY IS NULL
AND B.PKEY IS NULL

● SELF JOIN
A∩B

SELECT <FIELD_LIST>
FROM TABLEA A INNER JOIN TABLEB B
ON A.PKEY = B.PKEY

0개의 댓글