Lecture

Multi-table Joins

You can join three or more tables in a single SQL query by chaining multiple JOIN operations.

This is common in normalized databases where data is separated across related tables.

By default, when you just write JOIN without specifying the type, most SQL databases interpret it as an INNER JOIN.


Syntax

Here is the syntax for a multi-table join:

Multi-table JOIN Syntax
SELECT ... FROM table1 JOIN table2 ON ... JOIN table3 ON ...;

Each JOIN connects one additional table to the growing result set.

Make sure each join condition (ON ...) clearly defines how the tables relate.


Example: Students, Enrollments, and Classes

As an example, let's say we have the following tables:

students

student_idname
1Alex
2Sara
3David
4Nina
5Michael

enrollments

student_idclass_id
1A1
2A2
3A1
4A3
5A2

classes

class_idclass_name
A1Math
A2History
A3Physics
A4Chemistry

Below is an example of a multi-table join between the students, enrollments, and classes tables.

Join 3 tables
SELECT students.name, classes.class_name FROM students JOIN enrollments ON students.student_id = enrollments.student_id JOIN classes ON enrollments.class_id = classes.class_id;

Result:

nameclass_name
AlexMath
SaraHistory
DavidMath
NinaPhysics
MichaelHistory

This query connects students to their enrollments, then maps those to class names.


When to Use Multi-table Joins

Use multi-table joins when:

  • You need a complete view across multiple related tables
  • You're working with a normalized schema
  • You're building reports that require joined context

Tip: Use clear and descriptive aliases to keep your queries readable.

Quiz
0 / 1

How do you connect multiple tables in an SQL query to retrieve related data?

In SQL, you can join three or more tables by using operations.
UNION
JOIN
GROUP BY
DISTINCT

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Tables

Execution Result