Back to Yugabyte Db

OUTER JOIN

community/learn/content/01-SQL-Basics/03-joins/02-outer-join.md

2026.1.0.0-b291.6 KB
Original Source

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;

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;

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;

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;

The query should return 464 rows.