# Join
# μ‘°μΈμ΄λ?
λ κ° μ΄μμ ν μ΄λΈμ΄λ λ°μ΄ν°λ² μ΄μ€λ₯Ό μ°κ²°νμ¬ λ°μ΄ν°λ₯Ό κ²μνλ λ°©λ²
ν μ΄λΈμ μ°κ²°νλ €λ©΄, μ μ΄λ νλμ μΉΌλΌμ μλ‘ κ³΅μ νκ³ μμ΄μΌ νλ―λ‘ μ΄λ₯Ό μ΄μ©νμ¬ λ°μ΄ν° κ²μμ νμ©νλ€.
# JOIN μ’ λ₯
- INNER JOIN
- LEFT OUTER JOIN
- RIGHT OUTER JOIN
- FULL OUTER JOIN
- CROSS JOIN
- SELF JOIN
# INNER JOIN
κ΅μ§ν©μΌλ‘, κΈ°μ€ ν μ΄λΈκ³Ό join ν μ΄λΈμ μ€λ³΅λ κ°μ 보μ¬μ€λ€.
SELECT A.NAME, B.AGE FROM EX_TABLE A INNER JOIN JOIN_TABLE B ON A.NO_EMP = B.NO_EMP
# LEFT OUTER JOIN
κΈ°μ€ν μ΄λΈκ°κ³Ό μ‘°μΈν μ΄λΈκ³Ό μ€λ³΅λ κ°μ 보μ¬μ€λ€.
μΌμͺ½ν μ΄λΈ κΈ°μ€μΌλ‘ JOINμ νλ€κ³ μκ°νλ©΄ νΈνλ€.
SELECT A.NAME, B.AGE FROM EX_TABLE A LEFT OUTER JOIN JOIN_TABLE B ON A.NO_EMP = B.NO_EMP
# RIGHT OUTER JOIN
LEFT OUTER JOINκ³Όλ λ°λλ‘ μ€λ₯Έμͺ½ ν μ΄λΈ κΈ°μ€μΌλ‘ JOINνλ κ²μ΄λ€.
SELECT A.NAME, B.AGE FROM EX_TABLE A RIGHT OUTER JOIN JOIN_TABLE B ON A.NO_EMP = B.NO_EMP
# FULL OUTER JOIN
ν©μ§ν©μ λ§νλ€. Aμ B ν μ΄λΈμ λͺ¨λ λ°μ΄ν°κ° κ²μλλ€.
SELECT A.NAME, B.AGE FROM EX_TABLE A FULL OUTER JOIN JOIN_TABLE B ON A.NO_EMP = B.NO_EMP
# CROSS JOIN
λͺ¨λ κ²½μ°μ μλ₯Ό μ λΆ ννν΄μ£Όλ λ°©μμ΄λ€.
Aκ° 3κ°, Bκ° 4κ°λ©΄ μ΄ 3*4 = 12κ°μ λ°μ΄ν°κ° κ²μλλ€.
SELECT A.NAME, B.AGE FROM EX_TABLE A CROSS JOIN JOIN_TABLE B
# SELF JOIN
μκΈ°μμ κ³Ό μκΈ°μμ μ μ‘°μΈνλ κ²μ΄λ€.
νλμ ν μ΄λΈμ μ¬λ¬λ² 볡μ¬ν΄μ μ‘°μΈνλ€κ³ μκ°νλ©΄ νΈνλ€.
μμ μ΄ κ°κ³ μλ μΉΌλΌμ λ€μνκ² λ³νμμΌ νμ©ν λ μμ£Ό μ¬μ©νλ€.
SELECT A.NAME, B.AGE FROM EX_TABLE A, EX_TABLE B
# [μ°Έκ³ ]
β - ν€(Key) - SQL Injection β