Lecture

Multi-table Joins

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

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

By default, if you 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 adds another table to the growing result set.

Ensure that each join condition (ON ...) clearly defines how the tables are related.


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 using 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 and then maps those enrollments to class names.


Why are multi-table joins important?

Multi-table joins are essential when:

  • You need a complete view across several related tables
  • You’re working with a normalized schema where data is stored across multiple tables
  • You’re building reports that require context from multiple sources

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

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