MySQL + SQL · Lesson 1
Join Three Tables
Joining Multiple Tables
You can chain JOINs to combine three or more tables — each JOIN links to the next on a common key.
Three-Table Join
SELECT s.name, c.course_name, t.teacher_name
FROM students s
JOIN enrollments e ON s.id = e.student_id
JOIN courses c ON e.course_id = c.id
JOIN teachers t ON c.teacher_id = t.id;
How it Works
Each JOIN connects two tables on a shared key. Chain them so students link to enrollments, enrollments to courses, and courses to teachers.
Summary
- Chain multiple JOIN ... ON clauses, each linking on a common key.
- Use table aliases (s, c, t) to keep the query short and clear.