๊ด€๋ฆฌ ๋ฉ”๋‰ด

JiYoung Dev ๐Ÿ–ฅ

[database ๊ณ ๊ธ‰] ์ง‘ํ•ฉ์—ฐ์‚ฐ์ž (2023.08.08) ๋ณธ๋ฌธ

full stack/database

[database ๊ณ ๊ธ‰] ์ง‘ํ•ฉ์—ฐ์‚ฐ์ž (2023.08.08)

Shinjio 2023. 8. 8. 17:43

 

UNION : ์ค‘๋ณต ์ œ๊ฑฐ

UNION ALL : ์ค‘๋ณต ํฌํ•จ

 

ํŠน์ง•1. 

์ปฌ๋Ÿผ์€ ์ฒซ๋ฒˆ์งธ ์ปฌ๋Ÿผ์„ ๋”ฐ๋ผ๊ฐ„๋‹ค. 

 

SELECT ์˜ˆ๋งค๋ฒˆํ˜ธ, ๋ฎค์ง€์ปฌ์ด๋ฆ„, ๋ฎค์ง€์ปฌ๊ฐ€๊ฒฉ 
  FROM ๋ฎค์ง€์ปฌ์˜ˆ๋งค๋‚ด์—ญ
  
UNION ALL

SELECT ์˜ˆ๋งค๋ฒˆํ˜ธ, ์ฝ˜์„œํŠธ์ด๋ฆ„, ์ฝ˜์„œํŠธ๊ฐ€๊ฒฉ
  FROM ์ฝ˜์„œํŠธ์˜ˆ๋งค๋‚ด์—ญ
  
UNION ALL

SELECT ์˜ˆ๋งค๋ฒˆํ˜ธ, ๊ทน์ด๋ฆ„, ๊ทน๊ฐ€๊ฒฉ
  FROM ๊ทน์žฅ์˜ˆ๋งค๋‚ด์—ญ ;

 

 

 

ํŠน์ง• 2. 

์ปฌ๋Ÿผ์˜ ๊ฐœ์ˆ˜์™€ ์ž๋ฃŒํ˜•์ด ์ผ์น˜ํ•ด์•ผ ํ•จ!

 

 

 

์ง์ ‘ ๋ฌธ์žํ˜•์ด๋‚˜ NULL๊ฐ’์„ ์ง€์ •ํ•˜์—ฌ ํ•ด๋‹น ์ปฌ๋Ÿผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. 

 

 

 

 

oracle ๋ฒ„์ „์— ๋”ฐ๋ฅธ ์ฐจ์ด 

<10๋ฒ„์ „> 
์ค‘๋ณต์ œ๊ฑฐ +  ์ •๋ ฌ = union
์ค‘๋ณต x + ์ •๋ ฌ x = union all

<11๋ฒ„์ „> (๊ณต๊ณต๊ธฐ๊ด€ ๋“ฑ์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์“ฐ๋Š” ๋ฒ„์ „)
union = ์ค‘๋ณต
union all = ์ค‘๋ณตx

<21c>
๊ฐ€์žฅ ์ตœ์‹  ๋ฒ„์ „์ด๋‚˜ ์ž˜๋ชป ์—…๊ทธ๋ ˆ์ด๋“œํ–ˆ๋‹ค๊ฐ€ ๊ธฐ์กด๊ฒŒ ์ž‘๋™์•ˆํ•  ์ˆ˜ ์žˆ์Œ