๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

SET_OPERATION

๊ณผ๋ชฉ
ORACLE
ํƒœ๊ทธํ•ญ๋ชฉ
ORACLE
SET_OPERATION
UNION
UNIONALL
INTERSECT
MINUS
Study Date
2020/12/20
์†์„ฑ

SET_OPERATION

SET OPERATION (์ง‘ํ•ฉ์—ฐ์‚ฐ) UNION : ํ•ฉ์ง‘ํ•ฉ UNION ALL : ๊ณตํ†ต๋œ๋ถ€๋ถ„์„ ๋‘๋ฒˆ๋”ํ•œ๊ฑฐ (๊ต์ง‘ํ•ฉ๋ถ€๋ถ„์„ ์ œ์™ธํ•˜์ง€ ์•Š๊ณ  ๊ทธ๋Œ€๋กœ๋”ํ•œ๊ฑฐ) INTERSECT : ๊ต์ง‘ํ•ฉ MINUS : ์ฐจ์ง‘ํ•ฉ
SQL
๋ณต์‚ฌ
1. UNION : ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ํ•˜๋‚˜๋กœ ํ•ฉ์น˜๋Š” ์—ฐ์‚ฐ์ž์ด๋‹ค ์ค‘๋ณต๋œ ์˜์—ญ์„ ์ œ์™ธํ•˜์—ฌ ํ•˜๋‚˜๋กœ ํ•ฉ์นœ๋‹ค.(๋งŽ์ด์“ฐ์ž„) EX) SELECT EMP_ID , EMP_NAME , DEPT_CODE , SALARY FROM EMPLOYEE WHERE DEPT_CODE = 'D5' UNION SELECT EMP_ID , EMP_NAME , DEPT_CODE , SALARY FROM EMPLOYEE WHERE SALARY > 3000000; --------------------------------------------------------------- 2. UNION ALL : ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ํ•˜๋‚˜๋กœ ํ•ฉ์น˜๋Š” ์—ฐ์‚ฐ์ž UNION๊ณผ์˜ ์ฐจ์ด์ ์€ ์ค‘๋ณต์˜์—ญ์„ ๋ชจ๋‘ ํฌํ•จ์‹œํ‚จ๋‹ค. SELECT EMP_ID , EMP_NAME , DEPT_CODE , SALARY FROM EMPLOYEE WHERE DEPT_CODE = 'D5' UNION ALL SELECT EMP_ID , EMP_NAME , DEPT_CODE , SALARY FROM EMPLOYEE WHERE SALARY > 3000000; ---------------------------------------------------------------- SELECT DEPT_CODE , JOB_CODE , SUM(SALARY) FROM EMPLOYEE GROUP BY ROLLUP(DEPT_CODE, JOB_CODE) UNION SELECT '' >>์ปฌ๋Ÿผ์ˆ˜๋ฅผ ๋งž์ถฐ์ฃผ๊ธฐ ์œ„ํ•ด์„œ ''๋ฅผ ์ถ”๊ฐ€ํ•จ , JOB_CODE , SUM(SALARY) FROM EMPLOYEE GROUP BY ROLLUP(DEPT_CDOE ,JOB_CODE) ORDER BY 1; ---------------------------------------------------------------------------- 3. INTERSECT : ์—ฌ๋Ÿฌ๊ฐœ์˜ SELCTํ•œ ๊ฒฐ๊ณผ์—์„œ ๊ณตํ†ต๋ถ€๋ถ„๋งŒ ๊ฒฐ๊ณผ๋กœ ์ถ”์ถœ ์ˆ˜ํ•™์—์„œ ๊ต์ง‘ํ•ฉ๊ณผ ๋น„์Šท SELECT EMP_ID , EMP_NAME , DEPT_CODE , SALARY FROM EMPLOYEE WHERE DEPT_CODE = 'D5' INTERSECT SELECT EMP_ID , EMP_NAME , DEPT_CODE , SALARY FROM EMPLOYEE WHERE SALARY > 3000000; ------------------------------------------------------------------- 4. MINUS : ์„ ํ–‰ SELECT ๊ฒฐ๊ณผ์—์„œ ํ›„ํ–‰ SELECT ๊ฒฐ๊ณผ์™€ ๊ฒน์น˜๋Š”๋ถ€๋ถ„์„ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ๋ถ€๋ถ„๋งŒ ์ถ”์ถœ, ์ˆ˜ํ•™์—์„œ ์ฐจ์ง‘ํ•ฉ๊ณผ ๋น„์Šทํ•˜๋‹ค. SELECT EMP_ID , EMP_NAME , DEPT_CODE , SALARY FROM EMPLOYEE WHERE DEPT_CODE = 'D5' MINUS SELECT EMP_ID , EMP_NAME , DEPT_CODE , SALARY FROM EMPLOYEE WHERE SALARY > 3000000;
SQL
๋ณต์‚ฌ