Database Programming with
SQL 6-3: Inner versus Outer
Joins Practice Solutions
Vocabulary
Directions: Identify the vocabulary word for each definition below.
FULL OUTER JOIN Performs a join on two tables, retrieves all the rows in the
Left table, even if there is no match in the Right table. It
also retrieves all the rows in the Right table, even if there
is no match in the Left table.
Outer join A join that returns the unmatched rows as well as
matched rows
LEFT OUTER JOIN Performs a join on two tables, retrieves all the rows in the
Left table even if there is no match in the Right table
RIGHT OUTER Performs a join on two tables, retrieves all the rows in the
JOIN Right table even if there is no match in the Left table
Inner join A join of two or more tables that returns only matched
rows
Try It / Solve It
Use the Oracle database for problems 1-7.
1. Return the first name, last name, and department name for all employees including
those employees not assigned to a department.
Solution:
SELECT e.first_name, e.last_name, d.department_id
FROM employees e
LEFT OUTER JOIN departments d
ON( e.department_id = d.department_id);
2. Return the first name, last name, and department name for all employees including
those departments that do not have an employee assigned to them.
Solution:
SELECT e.first_name, e.last_name, d.department_id
FROM employees e
RIGHT OUTER JOIN departments d
ON( e.department_id = d.department_id);
3. Return the first name, last name, and department name for all employees including those
departments that do not have an employee assigned to them and those employees not
assigned to a department.
2
Solution:
SELECT e.first_name, e.last_name, d.department_id
FROM employees e
FULL OUTER JOIN departments d
ON( e.department_id = d.department_id);
4. Create a query of the DJs on Demand database to return the first name, last name, event
date, and description of the event the client held. Include all the clients even if they have not
had an event scheduled.
Solution:
SELECT c.first_name, c.last_name, e.event_date, e.description
FROM d_clients c LEFT OUTER JOIN d_events e
ON(c.client_number = e.client_number);
5. Using the Global Fast Foods database, show the shift description and shift assignment date
even if there is no date assigned for each shift description.
Solution:
SELECT s.description, a.shift_assign_date
FROM f_shifts s LEFT OUTER JOIN f_shift_assignments a ON (s.code = a.code);