Home › Learn › SQL › Joins

INNER JOIN

Lesson 16 of 26. Combine rows from two tables that belong together.

Orders store a customer_id, not the customer's name; the name lives in customers. A join lines the two up: FROM orders JOIN customers ON customers.id = orders.customer_id produces one row per order with the matching customer's columns attached. The ON condition says which rows belong together, almost always a key in one table equal to a foreign key in the other.

When both tables have a column with the same name (id, name), prefix it with the table name so the database knows which one you mean. JOIN on its own means INNER JOIN: rows with no match on either side are left out.

SELECT employees.name, managers.name
FROM employees JOIN employees AS managers ON managers.id = employees.manager_id;

Your task

Show each order's customer name (from customers) and its ordered_at date, one row per order.

Hint 1

JOIN customers ON customers.id = orders.customer_id

Show the solution
SELECT customers.name, orders.ordered_at
FROM orders JOIN customers ON customers.id = orders.customer_id;

    Runs SQLite compiled to WebAssembly in this tab; the database is rebuilt before every run.