1. 사원 'SEO JOHN'의 정보를 얻자
STUDY/ORACLE_SQL_2일차 2007. 6. 22. 13:33사원 'SEO JOHN'의 정보를 얻자
사원, 사원이름, 부서이름
1) 사원 테이블로부터 사번, 사원이름, 부서 아이디를 얻는다.
SELECT employee_id, last_name, department_id
FROM employees
WHERE UPPER(last_name) = 'SEO'
AND UPPER(first_name) = 'JOHN'
FROM employees
WHERE UPPER(last_name) = 'SEO'
AND UPPER(first_name) = 'JOHN'
2) 사원 테이블의 부서 아이디를 참고하여
부서 테이블로부터 부서 이름을 얻는다.
SELECT department_name
FROM departments
WHERE department_id = 50
SELECT employee_id, last_name, department_name
FROM employees, departments
WHERE UPPER(last_name) = 'SEO'
AND UPPER(first_name) = 'JOHN'
AND employess.department_id = departments.department_id;
FROM employees, departments
WHERE UPPER(last_name) = 'SEO'
AND UPPER(first_name) = 'JOHN'
AND employess.department_id = departments.department_id;
join 으로 다듬기 (가독성 향상)
SELECT employee_id, last_name, department_name
FROM employees e JOIN departments d
ON e.department_id = d.department_id
WHERE UPPER(last_name) = 'SEO'
AND UPPER(first_name) = 'JOHN';