Overview
Put customer names next to their orders with JOIN ... ON, and see why a missing ON condition multiplies every row.
- JOIN ... ON
- Table aliases
- Only matching rows are kept
Short Course
JOIN ... ON combines rows of two tables that match on a key. Trap: forget
or mistype the ON condition and every order pairs with every customer, a
cross join that multiplies rows without any error.
SELECT o.id, c.name
FROM orders AS o
JOIN customers AS c ON c.id = o.customer_id;
Task
Return the id, the customer's name and the total of every order over 50,
ordered by order id. In the database below, order 10 belongs to Ana.
Database
Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.
| idINTEGER | nameTEXT |
|---|---|
| 1 | Ana |
| 2 | Bo |
| 3 | Cy |
| idINTEGER | customer_idINTEGER | totalREAL |
|---|---|---|
| 10 | 1 | 80.0 |
| 11 | 2 | 20.0 |
| 12 | 3 | 55.5 |
| 13 | 1 | 51.0 |
Test Suites
Pending
Next
Output