0% found this document useful (0 votes)
25 views11 pages

Lessión 4

The document contains SQL queries that join data from the employees and departments tables to retrieve employee and department information. The queries use inner joins, outer joins, natural joins, and cross joins to combine data from the tables based on matching column values. Some queries filter the results to specific employees or departments.

Uploaded by

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

Lessión 4

The document contains SQL queries that join data from the employees and departments tables to retrieve employee and department information. The queries use inner joins, outer joins, natural joins, and cross joins to combine data from the tables based on matching column values. Some queries filter the results to specific employees or departments.

Uploaded by

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

LESSIN 4

SELECT employees.employee_id, employees.last_name, employees.department_id,


departments.department_id, departments.location_id
FROM employees, departments
WHERE employees.department_id = departments.department_id

SELECT last_name, employees.department_id, department_name


FROM employees, departments
WHERE employees.department_id = departments.department_id
AND last_name = 'Matos';

SELECT e.employee_id, e.last_name, e.department_id,


d.department_id, d.location_id
FROM employees e, departments d
WHERE e.department_id = d.department_id;

SELECT e.last_name, d.department_name, l.city


FROM employees e, departments d, locations l
WHERE e.department_id = d.department_id
AND d.location_id = l.location_id;

SELECT e.last_name, e.department_id, d.department_name


FROM employees e, departments d
WHERE e.department_id = d.department_id;

SELECT e.last_name, e.department_id, d.department_name


FROM employees e, departments d
WHERE e.department_id(+) =d.department_id;

SELECT worker.last_name|| 'works for'


|| manager.last_name
FROM employees worker, employees manager
WHERE worker.manager_id =manager.employee_id;

SELECT last_name, department_name


FROM employees
CROSS JOIN departments;

SELECT department_id, department_name, location_id, city


FROM departments
NATURAL JOIN locations;

SELECT department_id, department_name, departments.location_id, city


FROM departments, locations
WHERE departments.location_id = locations.location_id;

SELECT department_id, department_name, location_id, city


FROM departments
NATURAL JOIN locations
WHERE department_id IN (20, 50);

SELECT e.employee_id, e.last_name, d.location_id


FROM employees e JOIN departments d
USING (department_id);

SELECT employee_id, last_name, employees.department_id, location_id


FROM employees, departments
WHERE employees.department_id = departments.department_id;

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);

SELECT e.last_name emp, m.last_name mgr


FROM employees e JOIN employees m
ON (e.manager_id = m.employee_id);

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;

SELECT employee_id, city, department_name


FROM employees, departments, locations
WHERE employees.department_id = departments.department_id
AND departments.location_id = locations.location_id;

SELECT e.last_name, e.department_id, d.department_name


FROM employees e
LEFT OUTER JOIN departments d
ON (e.department_id = e.department_id);

SELECT e.last_name, e.department_id, d.department_name


FROM employees e
RIGHT OUTER JOIN departments d
ON (e.department_id = e.department_id);

SELECT e.last_name, e.department_id, d.department_name


FROM employees e
FULL OUTER JOIN departments d
ON (e.department_id = d.department_id);

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;

You might also like