์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์—†์–ด์ง„ ๊ธฐ๋ก ์ฐพ๊ธฐ (SQL/JOIN)

PROGRAMMING/Database

by koharin 2021. 1. 23. 01:48

๋ณธ๋ฌธ

728x90
๋ฐ˜์‘ํ˜•

โœ” SQL JOIN


 

 

๐Ÿ“ LEFT EXCLUSIVE: ANIMAL_INS์— ์—†๋Š” ANIMAL_ID ๊ตฌํ•˜๊ธฐ


  • ์ž…์–‘์„ ๊ฐ„ ๊ธฐ๋ก(ANIMAL_OUTS)์€ ์žˆ๋Š”๋ฐ, ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๊ธฐ๋ก(ANIMAL_INS)์ด ์—†๋Š” ๋™๋ฌผ์€ Table A๋ฅผ ANIMAL_OUTS, Table B๋ฅผ ANIMAL_INS๋ผ๊ณ  ํ•  ๋•Œ, LEFT EXCLUSIVE JOIN์— ํ•ด๋‹นํ•œ๋‹ค.

  • LEFT EXCLUSIVE JOIN์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

SELECT [Select List]
FROM TableA A
LEFT OUTER JOIN TableB B
ON A.key = B.key
WHERE B.key IS NULL;

 

  • ์œ„์—์„œ ANIMAL_ID, NAME์„ ์กฐํšŒํ•˜๋Š”๋ฐ

  • LEFT OUTER JOIN์—์„œ ANIMAL_ID ์ค‘์—์„œ B์—๋Š” ์—†๋Š” ANIMAL_ID๋ฅผ ์กฐํšŒํ•œ๋‹ค.

 

๐Ÿ’ป MYSQL ์ œ์ถœ์ฝ”๋“œ


SELECT A.ANIMAL_ID, A.NAME
FROM ANIMAL_OUTS A
LEFT OUTER JOIN ANIMAL_INS B
ON A.ANIMAL_ID = B.ANIMAL_ID
WHERE B.ANIMAL_ID IS NULL;
728x90
๋ฐ˜์‘ํ˜•

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ