INNER JOIN
INNER JOIN returns only rows where the join condition matches in BOTH tables. Rows that don't match are excluded from the result. This is the most common join type and the default when you write just JOIN.
INNER JOIN Key Points
- Returns only MATCHING rows from both tables
- Unmatched rows are dropped — if user has no orders, they won't appear
- Written as JOIN or INNER JOIN (identical)
- Multiple INNER JOINs chain naturally for multi-table queries
- Most commonly used in production queries
INNER JOIN Examples on ecommerce_db
-- Join users with their orders
SELECT
u.name AS customer,
u.email,
o.id AS order_id,
o.total_amount,
o.status
FROM users u
INNER JOIN orders o ON u.id = o.user_id;
-- Result (Bob Lee not shown — no orders):
-- customer | email | order_id | total_amount | status
-- John Doe | john@... | 1 | 999.99 | delivered
-- John Doe | john@... | 3 | 89.99 | shipped
-- Alice Smith | alice@... | 2 | 599.99 | pending
-- Join orders with payments
SELECT
o.id AS order_id,
o.status,
p.amount AS paid,
p.payment_method
FROM orders o
INNER JOIN payments p ON o.id = p.order_id;
-- Only orders WITH payments appear
-- Three-table INNER JOIN
SELECT
u.name, o.id AS order_id, p.amount, p.payment_method
FROM users u
JOIN orders o ON u.id = o.user_id
JOIN payments p ON o.id = p.order_id;Quick Quiz
Tip
Tip
Practice INNER JOIN in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Relationships define how tables connect through foreign keys
Common Mistake
Warning
A common mistake with INNER JOIN is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready sql code.
Practice Task
Note
Practice Task — (1) Write a working example of INNER JOIN from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Key Takeaways
- INNER JOIN returns only rows where the join condition matches in BOTH tables.
- Returns only MATCHING rows from both tables
- Unmatched rows are dropped — if user has no orders, they won't appear
- Written as JOIN or INNER JOIN (identical)