Two tables, one answer — watch INNER JOIN link matching rows, and see what LEFT JOIN would do with the leftovers.
The big picture
Why tables live apart
Copying the same course name onto every student row would waste space and invite typos. Databases split data into tables and stitch them back together with JOINs.
1
One fact, one place
Students live in one table, courses in another. Nothing is duplicated between them.
2
Foreign key
A column like course_id points at a row in another table. It is the thread that connects them.
3
JOIN stitches
JOIN reads two tables at once and combines matching rows into single result rows.
4
INNER JOIN
Keeps only pairs that match on both sides. Unmatched rows are left out.
5
LEFT JOIN (outer)
Keeps every row of the left table — unmatched ones get NULL in the right-side columns.
Why tables live apart
One fact, one place1Students live in one table, courses in another. Nothing is duplicated between them.
Foreign key2A column like course_id points at a row in another table. It is the thread that connects them.
JOIN stitches3JOIN reads two tables at once and combines matching rows into single result rows.
INNER JOIN4Keeps only pairs that match on both sides. Unmatched rows are left out.
LEFT JOIN (outer)5Keeps every row of the left table — unmatched ones get NULL in the right-side columns.
5 building blocks make up Why tables live apart
Live query
Watch an INNER JOIN match rows
Press play: the engine tries to link every student to a course. Dashed lines show live matches.
SELECT name, title
FROM students
INNERJOIN courses
ON students.course_id = courses.course_id;
students
id
name
course_id
1
Ava
1
2
Ben
2
3
Chloe
9
4
Dev
3
courses
course_id
title
1
Databases
2
Java Basics
3
Robotics
Result
0 rows
name
title
press play — rows will appear here
Step 1/7
Ava took course_id 1 — the engine finds course 1, Databases, and draws the link.
Visualize
The matching loop behind a JOIN
For each student the engine hunts through the courses table looking for one matching id.
process decision input / output start / end
Challenge
Predict the LEFT JOIN
Same two tables, but the outer join refuses to drop anyone. What does the grid look like now?
leftjoin.sql
1-- students(id, name, course_id)
2-- 1 Ava 1 · 2 Ben 2 · 3 Chloe 9 · 4 Dev 3
3-- courses(course_id, title)
4-- 1 Databases · 2 Java Basics · 3 Robotics
5
6SELECT name, title
7FROM students
8LEFTJOIN courses
9ON students.course_id = courses.course_id;
Your predicted output — one line per console line
Hint: LEFT keeps every student. Chloe has no matching course — her title slot fills with NULL.
Practice
Match the join vocabulary
Click a term, then click its description to lock the pair.
5 conceptsTap a card to expand
?INNER JOINdrops into place
?LEFT JOINdrops into place
?ONdrops into place
?foreign keydrops into place
?primary keydrops into place
Recap
Key takeaways
Key takeaways5 takeaways
01
Tables stay small and clean; JOINs combine them at query time.
02
A foreign key (course_id) points into another table.
03
ON defines the match condition, tested for every row pair.
04
INNER JOIN drops unmatched rows from BOTH tables.
05
LEFT JOIN keeps every left row — missing matches arrive as NULL.