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.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 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ें.