Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

Part 05 / Topic 2 of 9

INNER JOIN

JOIN ... ON pairs each row with every row that matches the condition, and keeps only the pairs:

SELECT o.order_id, c.first_name, o.order_date, o.status
FROM orders AS o
JOIN customers AS c ON c.customer_id = o.customer_id
ORDER BY o.order_id
LIMIT 4;
 order_id | first_name | order_date |  status   
----------+------------+------------+-----------
        1 | Asha       | 2025-01-10 | delivered
        2 | Ravi       | 2025-01-25 | delivered
        3 | Asha       | 2025-02-14 | delivered
        4 | Meera      | 2025-02-20 | shipped
(4 rows)

Read the new pieces:

  • orders AS o — a table alias. With two tables in play, every column should say where it comes from; o. and c. keep that readable. (The AS is optional; the alias isn't, once queries grow.)
  • JOIN ... ON ... — plain JOIN means INNER JOIN: rows without a partner are dropped.

One customer never ordered (you found them in the Stage 1 project). In this result they simply don't exist — no order row carries their id, so no pair forms. Inner joins answer "show me the matches"; the next section is for when the non-matches matter.

🧪 Quick quiz — answer from memory, then check.

  1. What happens to a customers row with no matching order in an INNER JOIN?
  2. Why alias tables in a join?
Show the answers
  1. It's absent from the result — inner joins keep only matched pairs.
  2. So every column reference says which table it came from — shorter to type, impossible to misread, and required when both tables share a column name.

Done here? The practice set for Part 5 — 8 exercises with solutions — is on the part page.

Search the guide