Arcade
Join Room
Phase 05 · Backend EngineeringPlayable
Two tables, one exact result. Pick the join, and where the filter goes.
0 / 5 cleared
Level 1 · Only the matches
Every order, with the name of the customer who placed it. Orders belonging to nobody should not appear, and customers with no orders should not either.
users u
| id | name |
|---|---|
| 1 | Ada |
| 2 | Grace |
| 3 | Alan |
orders o
| id | user_id | total | status |
|---|---|---|---|
| 11 | 1 | 40 | paid |
| 12 | 1 | 25 | refunded |
| 13 | 2 | 90 | paid |
| 14 | 9 | 10 | paid |
Your query
SELECT * FROM users u INNER JOIN orders o ON u.id = o.user_id
Your result3 rows · matches
| u.id | u.name | o.id | o.user_id | o.total | o.status |
|---|---|---|---|---|---|
| 1 | Ada | 11 | 1 | 40 | paid |
| 1 | Ada | 12 | 1 | 25 | refunded |
| 2 | Grace | 13 | 2 | 90 | paid |
Target3 rows
| u.id | u.name | o.id | o.user_id | o.total | o.status |
|---|---|---|---|---|---|
| 1 | Ada | 11 | 1 | 40 | paid |
| 1 | Ada | 12 | 1 | 25 | refunded |
| 2 | Grace | 13 | 2 | 90 | paid |
INNER keeps only rows that matched. Notice what it silently removed: Alan, who has never ordered, and order 14, whose user_id points at a customer that does not exist. Both are the kind of thing you want to know about.
The result table is computed from the rows above it by the same rules a database applies, so the query printed here would produce exactly these rows against exactly these tables.