All SQL topics
SQL TOPIC

SQL JOIN exercises: combine tables

JOIN connects tables through a shared key, so you can see customer names next to their orders.

FROM orders JOIN customers ON customers.id = orders.customer_id pairs each order with its customer. INNER JOIN keeps only rows that match on both sides.

Give tables short aliases (o, c) and always write the ON condition: a join without it pairs every row with every other row.

Worked example

Show the first orders with the customer who placed them.

SELECT o.id, o.order_date, c.name
FROM orders o
JOIN customers c ON c.id = o.customer_id
ORDER BY o.id
LIMIT 5;
Result on the sample data
idorder_datename
12026-05-17Maria Papadopoulou
22026-04-20Maria Papadopoulou
32026-06-17Maria Papadopoulou
42026-01-28Maria Papadopoulou
52026-08-24Jonas Becker

Common mistakes

  • Forgetting the ON condition.
  • Summing order totals after joining order lines, which counts each order once per line.