Loading…
INNER JOIN is one of the most powerful SQL concepts. It combines rows from two tables where they have matching values.
Real databases split data into multiple tables to avoid repetition. For example:
customers table: customer info (name, email)orders table: order info (date, status, customer_id)To see "which customer placed which order", we need to JOIN them.
SELECT columns
FROM table1
INNER JOIN table2 ON table1.column = table2.column;
SELECT orders.id, customers.name
FROM orders
INNER JOIN customers ON orders.customer_id = customers.id;
For each order, SQL finds the customer whose id matches the order's customer_id.
| orders.id | orders.customer_id | → | customers.id | customers.name |
|---|---|---|---|---|
| 1 | 101 | → | 101 | Alice |
| 2 | 102 | → | 102 | Bob |
If a customer has no orders, they won't appear. If an order has no matching customer, it won't appear either.
orders: id, customer_id, order_date, statuscustomers: id, name, emailJoin orders with customers to show:
Downloading SQL engine… (one-time)
This runs entirely in your browser and is cached for next time.