hyeonga_code
Database_30_ANSI JOIN_조인 함수 3 WAY JOIN 본문
-- 조인_JOIN
-- 데이터베이스에서 여러 테이블의 데이터가 필요한 경우 조인 조건을 사용합니다.
-- 서로 대응되는 열에 존재하는 공통 값에 따라 한 테이블의 행을 다른 테이블의 행에 조인할 수 있습니다.
-- 매칭되는 컬럼이 조회 데이터에 포함되어 있지 않아도 무관합니다.
-- 3-WAY
-- ON 절을 사용하여 세 테이블을 조인합니다.
-- 작성한 순서대로 조인을 진행합니다.
-- 4개 이상의 테이블을 조인할 수는 있습니다. >> 스타 조인?
SELECT e.employee_id, e.last_name, e.job_id, d.department_name, l.city
FROM employees e JOIN departments d
ON (e.department_id = d.department_id)
JOIN locations l
ON (d.location_id = l.location_id);
/*
EM_ID LAST_NAME JOB_ID DP_NAME CITY
-------------------------------------------------------------------------------------------
100 King AD_PRES Executive Seattle
101 Kochhar AD_VP Executive Seattle
102 De Haan AD_VP Executive Seattle
103 Hunold IT_PROG IT Southlake
104 Ernst IT_PROG IT Southlake
107 Lorentz IT_PROG IT Southlake
124 Mourgos ST_MAN Shipping South San Francisco
141 Rajs ST_CLERK Shipping South San Francisco
142 Davies ST_CLERK Shipping South San Francisco
143 Matos ST_CLERK Shipping South San Francisco
144 Vargas ST_CLERK Shipping South San Francisco
149 Zlotkey SA_MAN Sales Oxford
174 Abel SA_REP Sales Oxford
176 Taylor SA_REP Sales Oxford
200 Whalen AD_ASST Administration Seattle
201 Hartstein MK_MAN Marketing Toronto
202 Fay MK_REP Marketing Toronto
205 Higgins AC_MGR Accounting Seattle
206 Gietz AC_ACCOUNT Accounting Seattle
*/
SELECT e.employee_id, l.city, d.department_name
FROM employees e JOIN departments d
ON (d.department_id = e.department_id)
JOIN locations l
ON (d.location_id = l.location_id);
/*
EM_ID CITY DP_NAME
------------------------------------------------------------
100 Seattle Executive
101 Seattle Executive
102 Seattle Executive
103 Southlake IT
104 Southlake IT
107 Southlake IT
124 South San Francisco Shipping
141 South San Francisco Shipping
142 South San Francisco Shipping
143 South San Francisco Shipping
144 South San Francisco Shipping
149 Oxford Sales
174 Oxford Sales
176 Oxford Sales
200 Seattle Administration
201 Toronto Marketing
202 Toronto Marketing
205 Seattle Accounting
206 Seattle Accounting
*/
'Oracle Database' 카테고리의 다른 글
Database_32_ANSI JOIN_SELF JOIN 셀프 조인 (0) | 2023.07.31 |
---|---|
Database_31_ANSI JOIN_조인 함수 테이블의 접두어 사용 (0) | 2023.07.30 |
Database_29_ANSI JOIN_조인 함수 JOIN하려는 컬럼 이름이 다른 경우 (0) | 2023.07.30 |
Database_28_ANSI JOIN_조인 함수 두 개 이상의 컬럼이 겹치는 경우 USING 절 사용하기 (0) | 2023.07.30 |
Database_27_ANSI JOIN_조인 함수 Natural JOIN (0) | 2023.07.30 |