OUTER JOIN

SELECT with a LEFT OUTER JOIN

In this exercise we will query the customers table using a LEFT JOIN with the orders table.

SELECT DISTINCT customers.company_name,
customers.contact_name,
orders.ship_region
FROM customers
LEFT JOIN orders ON customers.region = orders.ship_region
ORDER BY company_name DESC;
Run in terminal

The query should return 91 rows.

SELECT with RIGHT OUTER JOIN

In this exercise we will query customers table using a FULL OUTER JOIN on orders.

SELECT DISTINCT customers.company_name,
customers.contact_name,
orders.ship_region
FROM customers
RIGHT OUTER JOIN orders ON customers.region = orders.ship_region
ORDER BY company_name DESC;
Run in terminal

The query should return 33 rows.

SELECT with FULL OUTER JOIN

In this exercise we will query the customers table using a FULL OUTER JOIN with the orders table.

SELECT DISTINCT customers.company_name,
customers.contact_name,
orders.ship_region
FROM customers
FULL OUTER JOIN orders ON customers.region = orders.ship_region
ORDER BY company_name DESC;
Run in terminal

The query should return 93 rows.

SELECT with FULL OUTER JOIN with only unique rows in both tables

In this exercise we will query the employees table using a FULL OUTER JOIN on the orders table using only the unique rows in each table.

SELECT DISTINCT employees.employee_id,
employees.last_name,
orders.customer_id
FROM employees
FULL OUTER JOIN orders ON employees.employee_id = orders.employee_id;
Run in terminal

The query should return 464 rows.