Multiple JOINs

Basic SQL
≈ 1 min read

A query can join additional tables step by step

In a real schema, the data you need is often spread across more than two tables. SQL allows several JOINs in sequence, and each next JOIN works with the intermediate result built so far.

SELECT
    o.id,
    u.name,
    p.name AS product_name
FROM orders AS o
JOIN users AS u ON u.id = o.user_id
JOIN products AS p ON p.id = o.product_id;

First, an order is matched with a user, then that result is enriched with product data. Each ON condition should describe one specific relationship between tables.

Read a complex join step by step

When many tables are involved, do not try to read the query as one long construction. First identify the base table after FROM, then answer two questions for every JOIN: what is being added and by which condition.

Several JOINs can unexpectedly multiply rows. If one row on the left matches several rows on the right, several result rows are produced. Across a chain of joins, this effect can accumulate, so always understand the cardinality of each relationship.