Lesson 21 of 30
70%
INNER JOIN
A JOIN stitches rows from two tables using a matching key.
INNER JOIN keeps only pairs that match on both sides.
Think of two stacks of cards. You keep a pair when the numbers line up.
The pattern
ON says how rows find each other. Usually table.column = other.column.
sql
Result
| name | points |
|---|---|
| Ada | 95 |
| Ada | 88 |
| Sam | 90 |
3 rows
Why not one giant table?
If Ada has three scores, you do not want to copy Ada's name three times in students.
Keep facts in one place. Join when you need the picture together.
Table nicknames
Short aliases keep the line readable.
sql
Result
| name | points |
|---|---|
| Ada | 95 |
| Sam | 90 |
2 rows
No match, no row
A student with no scores does not appear in an INNER JOIN.
A score with a missing student also disappears. That is the inner rule.
Tip: Always JOIN on keys, not on names. Names repeat. Ids should not.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.