๐Ÿ™ ์กฐ์ธ (JOIN)

์กฐ์ธ (JOIN)

๋ณดํ†ต PK์™€ FK๊ฐ’์˜ ์—ฐ๊ด€์— ์˜ํ•ด JOIN์ด ์„ฑ๋ฆฝ

  • INNER JOIN : ์กฐ์ธ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ํ–‰์— ๋Œ€ํ•ด์„œ๋งŒ ๊ฒฐ๊ณผ๊ฐ’์ด ๋‚˜์˜ค๋Š” ์กฐ์ธ
    • EQUI JOIN : =(equal) ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์กฐ์ธ

      • JOIN ON : ๊ณตํ†ต๋œ ์ด๋ฆ„์˜ ์ปฌ๋Ÿผ์ด ์—†๋Š” ๊ฒฝ์šฐ์กฐ์ธ ์กฐ๊ฑด์€ ON์— ๋‘์–ด ์‚ฌ์šฉํ•œ๋‹ค.
      FROM employees a
      JOIN titles b ON ( a.emp_no = b.emp_no )
      WHERE a.gender = 'f' AND b.title = 'Engineer';
      
    • NATURAL JOIN : ๋ณ„๋‹ค๋ฅธ ์กฐ๊ฑด์—†์ด ๋ฌต์‹œ์ ์œผ๋กœ ๊ณตํ†ต์ปฌ๋Ÿผ์„ ์ด์šฉํ•ด ์กฐ์ธ๋˜๋Š” ์œ ํ˜• โ—๏ธ NAUTRAL JOIN์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ปฌ๋Ÿผ์ด ๊ณตํ†ต์ปฌ๋Ÿผ์— ์†ํ•˜๊ฒŒ ๋˜๋Š” ์œ„ํ—˜์„ฑ์ด ์กด์žฌํ•œ๋‹ค.

      SELECT *
      FROM employees
      NATURAL JOIN titles;
      
    • JOIN ~ USING : ์‚ฌ์šฉ๋˜๋Š” ํ…Œ์ด๋ธ”๊ฐ„์— ๋™์ผํ•œ ์ด๋ฆ„๊ณผ ํ˜•์‹์˜ ์ปฌ๋Ÿผ์ด ๋‘˜ ์ด์ƒ์ธ ๊ฒฝ์šฐ USING(์ปฌ๋Ÿผ)์˜ ํ˜•์‹์œผ๋กœ ์กฐ์ธํ•˜๋Š” ์œ ํ˜•

      SELECT ์ปฌ๋Ÿผ, ์ปฌ๋Ÿผ, โ€ฆ
      FROM ํ…Œ์ด๋ธ”1
      JOIN ํ…Œ์ด๋ธ”2 USING(์กฐ์ธ ์ปฌ๋Ÿผ)
      [JOIN ํ…Œ์ด๋ธ”3 USING(์กฐ์ธ ์ปฌ๋Ÿผ)] โ€ฆ
      WHERE ๊ฒ€์ƒ‰ ์กฐ๊ฑด;
      
    • JOIN ~ ON : ๊ณตํ†ต๋œ ์ด๋ฆ„์˜ ์นผ๋Ÿผ์ด ์—†๋Š” ๊ฒฝ์šฐ ๊ฐ€์žฅ ๋ณดํŽธ์ ์œผ๋กœ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ๋Š” ์œ ํ˜•

      FROM employees a
      JOIN titles b ON (  a.emp_no = b.emp_no  )
      
  • OUTER JOIN : JOIN ์กฐ๊ฑด์—์„œ ๋™์ผํ•œ ๊ฐ’์ด ์—†๋Š” ํ–‰๋„ ๋ฐ˜ํ™˜ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค ์ฆ‰ A, B ํ…Œ์ด๋ธ”์„ JOIN ํ•  ๊ฒฝ์šฐ, ์กฐ๊ฑด์— ๋งž์ง€ ์•Š๋Š” ๋ฐ์ดํ„ฐ๋„ ํ‘œ์‹œํ•˜๊ณ  ์‹ถ์„ ๋•Œ OUTER JOIN์„ ์‚ฌ์šฉํ•œ๋‹ค enter image description here