You are on page 1of 2

092.

- INSERT WITH SELECT

insert into departments (DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID,


LOCATION_ID)
select e.department_id + 300, j.job_title , min(e.employee_id) , 1700
from employees e join jobs j on (e.job_id = j.job_id)
where e.job_id like '%_MAN'
group by e.department_id, j.job_title;

093.- INSERT: Subquery values

insert into employees


values(220, 'Patricia', 'Molina', 'patri@gmail.com', null, current_date, 'IT_PROG',
(select jobs.min_salary from jobs where jobs.job_id = 'IT_PROG'),
(select max(commission_pct) from employees ),
(select manager_id from departments where department_name = 'IT'),
(select department_id from departments where departments.department_name =
'IT'));

094.- UPDATE: Subquery values

update departments
set location_id = (select location_id from locations
where country_id = 'CN')
where department_name = 'IT';

095.- UPDATE: Subquery values

update departments
set manager_id = (select employee_id from employees where manager_id = (select
employee_id from employees where last_name = 'Hunold')
and hire_date = (select min(hire_date) from employees where manager_id = (select
employee_id from employees where last_name = 'Hunold')))
where manager_id = (select employee_id from employees where last_name =
'Hunold');
096.- DELETE: Subquery values

delete from departments


where department_id in (select department_id
from departments d
except
select department_id
from departments d2
where department_id in (select department_id from employees e));

You might also like