Ira SQL ProIra SQL Pro

Joining Three Tables

beginnerjoins
2 min read

How to Join Three Tables

To combine data from three tables, chain multiple JOIN clauses. Each JOIN connects two tables via a shared key. This is common with bridge/junction tables.

Syntax

SELECT columns
FROM table1
JOIN table2 ON table1.key = table2.fk
JOIN table3 ON table2.key2 = table3.fk;

When to Use

  • Connecting entities through a junction table (students → enrollments → courses)
  • Building reports that span multiple related tables
  • Any time you need data from three or more tables in one query

Key Points

  1. Chain JOINs — Each JOIN clause adds one more table to the query.
  2. Junction Tables — Many-to-many relationships require a bridge table in the middle.
  3. Aliases — Use short aliases (s, e, c) to keep the query readable.
  4. Mix Types — You can mix INNER JOIN, LEFT JOIN, etc. in the same query.
  5. Order — Start with the table that makes the most logical sense, then join related tables.

Guided Practice

Solve the challenge below. Use hints when stuck and check your answer for instant feedback.

Practice challengeGuided learning mode

Joining Three Tables Challenge

Write a query that solve this task: join students, enrollments, and courses to see who is enrolled where.

Expected result

Each student-course combination showing student name and course name.

Hidden checks

  • Returned rows and values
  • Output columns and result shape
  • Final database state after the query runs

Lesson guidance

How to Join Three Tables

Initializing database...Each run starts from fresh sample data.

More Examples

Three-table join with filtering

Find grade-A students and their courses.

Initializing database...Each run starts from fresh sample data.

Frequently Asked Questions

Is there a limit to how many tables I can join?
There is no fixed SQL limit, but performance may degrade with many joins. PostgreSQL handles dozens of joins, but keep queries as simple as possible.
Does the order of JOINs matter?
Logically, no — the optimizer rearranges joins. But writing them in a logical order (primary → junction → related) improves readability.

Related Topics