https://www.w3schools.com/mysql/mysql_join_cross.asp
https://www.w3schools.com/Sql/sql_join_full.asp
W3Schools.com
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
* w3schools.com ์์ ๊ฐ JOIN์ ํํํ๊ณ ์๋ ๊ทธ๋ฆผ์ด ๋์ผํ๋ค.
1๏ธโฃ ํฌ๋ก์ค ์กฐ์ธ (Cross Join)
์ค๋ช
- ํฌ๋ก์ค ์กฐ์ธ์ ๋ ํ ์ด๋ธ์ ๋ชจ๋ ์กฐํฉ์ ์์ฑํ๋ ์กฐ์ธ์ ๋๋ค.
- ์ฆ, ๊ฐ ํ ์ด๋ธ์ ๋ชจ๋ ํ์ ๊ณฑํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํฉ๋๋ค.
- ๊ฒฐ๊ณผ์ ์ผ๋ก ๊ฒฐ๊ณผ ์งํฉ์ ํ ์๋ ์ฒซ ๋ฒ์งธ ํ ์ด๋ธ์ ํ ์์ ๋ ๋ฒ์งธ ํ ์ด๋ธ์ ํ ์์ ๊ณฑ์ ๋๋ค.
- ์ด ์กฐ์ธ์ ON ์ ์ ์ฌ์ฉํ์ง ์์ต๋๋ค.
์์
- tableA
id name 1 Alice 2 Bob - tableB
id product 1 Widget 2 Gadget - ํฌ๋ก์ค ์กฐ์ธ ์ฟผ๋ฆฌ
SELECT * FROM tableA CROSS JOIN tableB;
- ๊ฒฐ๊ณผ
id name id product 1 Alice 1 Widget 1 Alice 2 Gadget 2 Bob 1 Widget 2 Bob 2 Gadget - ํ ์: 4ํ (2ํ * 2ํ)
2๏ธโฃ ํ ์กฐ์ธ (Full Outer Join)
์ค๋ช
- ํ ์กฐ์ธ์ ๋ ํ ์ด๋ธ ๊ฐ์ ๋ชจ๋ ํ์ ํฌํจํ๋ฉฐ, ์ผ์นํ์ง ์๋ ๊ฒฝ์ฐ์๋ `NULL`๋ก ํ์๋ฉ๋๋ค.
- ์ฆ, ์ผ์ชฝ ํ ์ด๋ธ์ ๋ชจ๋ ํ๊ณผ ์ค๋ฅธ์ชฝ ํ ์ด๋ธ์ ๋ชจ๋ ํ์ ํฌํจํ๊ณ , ๋ ํ ์ด๋ธ์ ์ผ์นํ์ง ์๋ ๋ถ๋ถ๋ ํฌํจ๋ฉ๋๋ค.
์์
- tableA
id name 1 Alice 2 Bob - tableB
id product 1 Widget 3 Gadget - ํ ์กฐ์ธ ์ฟผ๋ฆฌ
SELECT * FROM tableA FULL OUTER JOIN tableB ON tableA.id = tableB.id; -- ์กฐ์ธ ์กฐ๊ฑด ์ค์ โจ
- ๊ฒฐ๊ณผ
id name id product 1 Alice 1 Widget 2 Bob NULL NULL NULL NULL 3 Gadget - ํ ์: 3ํ (2ํ + 1ํ (tableB์ id 3์ ๋ํ NULL) + 1ํ (tableA์ id 2์ ๋ํ NULL))