skip to today's puzzle

A JOIN connects two tables

Data is often split across tables: customers in one, orders in another. JOIN lets one query use both, and ON says which two columns to compare — here each order's customer_id against the customer's id. Where the values match, the customer and the order are shown together on one row. A plain JOIN is an INNER JOIN: it only keeps rows that matched on both sides.

A tiny example

In plain English: Show me each customer’s name next to the total of their order.

SELECT c.name, o.total
FROM customers c
JOIN orders o
  ON o.customer_id = c.id;

Query result

nametotal
Amara8.5
Amara3.25
Theo12
Jin4.75

Each order found its customer by matching customer_id to the customer’s id, so the two sit side by side. Amara has two orders, so she shows up once for each.

See every JOIN type side by side in the SQL JOIN diagram & cheat sheet.

Common questions

What does the ON clause do in a JOIN?
ON says how rows from the two tables pair up, usually a foreign key against a primary key, such as orders.customer_id = customers.id. Rows without a partner are dropped by a plain JOIN.
What happens if I forget the ON clause?
Most databases either refuse the query or produce a cross join: every row from the first table paired with every row from the second, which is almost never what you want.

Related SQL lessons

Practice JOIN step by step

The Foundations Track has beginner puzzles built around this idea. Tap tiles, see real results. No terminal, no setup.

practice this in the course

Ready for a break?

A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.

Try today's free SQL puzzle