SQL Tutorial 0/85 lessons ~6 min read Lesson 36
INNER JOIN
INNER JOIN returns rows where the join condition matches in both tables.
Course progress0%
Focus
6 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
INNER JOIN returns rows where the join condition matches in both tables. Unmatched rows are dropped. The default and most-used join.
Understanding the topic
Core concepts to understand:
FROM a JOIN b ON a.id = b.a_id.- Drops rows with no match on either side.
- Multiple inner joins chain naturally.
- Best with indexed join columns.
- Equivalent to
WHEREwith the same predicate (older syntax).
Syntax reference
Visual workflow / architecture:
bash
users orders┌────┬──┐ ┌──────┬─────┐│ 1 │A │ │ user │amt ││ 2 │B │ │ 1 │ 10 ││ 3 │C │ │ 1 │ 20 │└────┴──┘ │ 2 │ 30 │ (no match for 3)└──────┴─────┘INNER JOIN ON users.id = orders.user_id→ 1A:10, 1A:20, 2B:30 (3C dropped)
Syntax Pattern
SELECT <cols>
FROM <a> [AS a]
INNER JOIN <b> [AS b]
ON <a.key> = <b.key>;INNER JOINReturns rows where the ON predicate matches in BOTH tables.ONJoin condition — usually FK = PK.dropsUnmatched rows on either side are excluded.
Live Example
sql
SELECT u.name, o.amountFROM users uINNER JOIN orders o ON o.user_id = u.id;
users + orders
| u.id | u.name | o.user_id | o.amount |
|---|---|---|---|
| 1 | Ana | 1 | 50 |
| 2 | Leo | 2 | 30 |
| 3 | Mia | — | — |
runs
joined
| name | amount |
|---|---|
| Ana | 50 |
| Leo | 30 |
Mia has no order, so she is dropped from the result.
Real-world use
Every joined report — orders + users, posts + authors, invoices + customers — uses INNER JOIN by default.
Best practices
- Index both sides of the join.
- Always alias tables in joins.
- Be explicit:
INNER JOINover comma-style joins.
Hands-on exercise
Interview preparation — practice these questions:
- Q1. What does INNER JOIN return?
- Q2. Difference vs CROSS JOIN.
- Q3. Performance impact of unindexed join columns.
- Q4. Equivalent old-style syntax.
- Q5. Inner join with multiple tables — how it chains.
Ready to mark this lesson complete?Track your journey across the entire course.