Multiple JOINs
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.
Check yourself
Exercise review
The mentor knows the solution and will help you reach it independently
Sign in to use the Mentor
The Mentor uses the current exercise and your conversation history.
Sign in
Review the key nuances and the answer after making your own attempt.
Sign in to view the solution
The solution and explanation are available after signing in.
Sign in