Keys
SQL · Unit 7: Joining tables
- Full plan
- SQL
- 10 exercises
You've spent six units reading ids by eye. "Customer 2" was Luke, "product 4" was the Cable, and every time it was you who went to the other table to check.
Today the warehouse has order 10 ready. Who does it go to, and what's in it? orders answers with numbers. Two other tables know who the 3 is and what the 7 is.
SELECT *
FROM orders
WHERE id = 10;Returns
| id | customer_id | product_id | quantity | placed |
|---|---|---|---|---|
| 10 | 3 | 7 | 2 | 2026-01-15 |
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Order 10 says
customer_id3. Who is that, and which city is the package going to? Fill in the blank to look them up incustomers.2. Predict the output
The row for order 10 says
customer_id3,product_id7, andquantity2. What does this query return?3. Complete the code
To find out whether a column repeats, you count its distinct values and compare that with the number of rows.
ordershas 12 rows. Fill in the blank with the column that never repeats.4. Multiple choice
ordershas three columns that hold id numbers:id,customer_id, andproduct_id. What is each one?5. Put the lines in order
Dylan is customer 6. Which orders has he placed, and on which days? Put in order the query that shows Dylan's orders, starting with the most recent. Two lines don't belong.
6. Predict the output
Customers 5 and 6 are Valerie and Dylan, with two orders each. Customers 7 and 8 are Hannah and Brian. What does this query return?
7. Multiple choice
The Mouse, which is product 2, drops in price. It's been sold in two orders, 3 and 7. In how many rows of the database does the price have to change?
8. Multiple choice
Each order points to its customer. Why not the other way around, with an
order_idcolumn incustomers?9. Write the code
The Cable, which is product 4, is running late, and the store is going to let the people who ordered it know. Write a query with a single column, the
customer_idof that product's orders, with no repeats and from lowest to highest.10. Find the bug
The biggest order the store has ever received is order 4, for 10 units. Its row in
orderssayscustomer_id4 andproduct_id4. Which product was it? The answer should be the Cable, but this query says Mason. Which line has the problem?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.