0% found this document useful (0 votes)
21 views1 page

Lab 6 and 7

The document provides examples of using different types of joins in SQL queries, including inner joins, outer joins, cross joins and self joins. It also provides examples of set operators like UNION, UNION ALL, INTERSECT and MINUS. The examples join tables like employees, departments, jobs, locations to select, filter and combine data from multiple tables.

Uploaded by

Fawad Amazon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Lab 6 and 7

The document provides examples of using different types of joins in SQL queries, including inner joins, outer joins, cross joins and self joins. It also provides examples of set operators like UNION, UNION ALL, INTERSECT and MINUS. The examples join tables like employees, departments, jobs, locations to select, filter and combine data from multiple tables.

Uploaded by

Fawad Amazon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Examples:

1.select e.employee_id,e.last_name,e.department_id,d.department_id,d.location_id
from employees e join departments d on (e.department_id = d.department_id);
2.select e.department_id,e.last_name,d.department_name from employees e left outer
join departments d on (e.department_id=d.department_id);
3.select e.department_id,e.last_name,d.department_name from employees e right outer
join departments d on (e.department_id=d.department_id);
4.select e.last_name,d.department_id,d.department_name from employees e full outer
join departments d on (e.department_id=d.department_id);
5.select e.last_name emp, m.last_name mgr from employees e join employees m on
(e.manager_id=m.employee_id);
6.select e.employee_id,e.last_name,e.department_id,d.department_id,d.location_id
from employees e join departments d on (e.department_id=d.department_id and
e.manager_id = 149);
7.select employee_id,city,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;
8.select last_name,department_name from employees cross join departments;

Q2.
select j.job_id,e.last_name,e.department_id from employees e join jobs j on
(e.job_id = j.job_id);
Q3.
select e.last_name,e.employee_id,e.manager_id,e.last_name from employees e join
employees m on
(e.manager_id = m.employee_id);

Lab 7
Examples:
1.SELECT employee_id, job_id FROM employees
UNION
SELECT employee_id, job_id FROM job_history;
2.SELECT employee_id, job_id, department_id FROM employees
UNION ALL
SELECT employee_id, job_id, department_id FROM job_history ORDER BY employee_id;
3.SELECT employee_id, job_id FROM employees
INTERSECT
SELECT employee_id, job_id FROM job_history;
4.SELECT employee_id From Employees
MINUS
SELECT employee_id FROM job_history;

You might also like