Starting Postgres in your browser…

Why join?

Good database design keeps each fact in one place. An order stores a customer_id, not the customer's name, so to see who placed each order you join orders to customers on that shared column.

Ctrl+Enter to run

Joining more than two tables

Joins chain together. Here each order item gets its order date and product name. The short names after AS (aliases) keep things readable.

Ctrl+Enter to run

LEFT JOIN keeps everything on the left

A plain JOIN (an inner join) drops rows that have no match. A LEFT JOIN keeps every row from the first table and fills the missing side with NULL.

Here every customer shows up, including the ones who have never ordered.

Ctrl+Enter to run

Try it

exercise Find the customers who have never placed an order. Show their first and last names. Hint: LEFT JOIN, then keep the rows where the order side is NULL.

Ctrl+Enter to run