728x90
반응형
--LEFT JOIUN
SELECT *
FROM TABLE A
LEFT JOIN TABLE B
ON A.ID = B.ID
WHERE B.KEY IS NULL
--;EFT JOIN
SELECT *
FROM, TABLE A
LEFT JOIN TABLE B
ON A.ID = B.ID
--INNER JOIN
SELECT *
FROM TABLE A
INNER JOIN TABLE B
ON A. KEY = B.KEY
--RIGHT JOIN
SELECT *
FROM TABLE A
RIGHT JOIN TABLE B
ON A.KEY = B.KEY
WHERE A.KEY IS NULL
--RIGHT JOIN
SELECT *
FROM TABLE A
RIGHT JOIN TABLE B
ON A.KEY = B.KEY
--FULL OUTER JOIN
SELECT *
FROM TABLE A
FULL OUTER JOIN TABLE B
ON A.KEY = B.KEY
MSSQL을 공부하면서 필요한 JOIN의 명령어들을 정리합니다.
아래의 사이트를 접속하면 화면에서 더 쉽게 볼 수 있습니다.
https://sql-joins.leopard.in.ua/
1) LEFT JOIN
SELECT * FROM TableA A
LEFT JOIN TableB B ON
A.key = B.key WHERE B.key IS NULL
SELECT * FROM TableA A
LEFT JOIN TableB B ON
A.key = B.key
2) INNER JOIN
SELECT * FROM TableA A
INNER JOIN TableB B ON
A.key = B.key
3) RIGHT JOIN
SELECT * FROM TableA A
RIGHT JOIN TableB B ON
A.key = B.key WHERE A.key IS NULL
SELECT * FROM TableA A
RIGHT JOIN TableB B ON
A.key = B.key
4) FULL OUTER JOIN
SELECT * FROM TableA A
FULL OUTER JOIN TableB B ON
A.key = B.key
728x90
반응형
'개발 > SQL' 카테고리의 다른 글
[SQL] USING 사용 방법 (0) | 2023.01.28 |
---|---|
[SQL] 테이블의 연산, MINUS, EXCEPT, INTERSECT, UNION (0) | 2023.01.28 |
[SQL] LEFT OUTER JOIN, RIGHT OUTER JOIN, INNER JOIN 설명 (0) | 2023.01.28 |
[SQL] MSSQL 실행순서 (0) | 2023.01.20 |
[MSSQL] CREATE TABLE, INSERT INTO, DROP TABLE (0) | 2022.08.24 |