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.
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.