Which table each column is from
SQL · Unit 7: Joining tables
- Full plan
- SQL
- 11 exercises
The warehouse finds each package by its order number. Which number is each customer waiting for? That number is the id, and as soon as the tables are joined there are two of them.
A JOIN builds a wide table, with all the columns of orders followed by all the columns of customers. This is the order dated January 20 with its customer next to it, and it has two id columns. The first is 12, the order number. The second is 2, and that's Luke.
SELECT *
FROM orders
JOIN customers
ON orders.customer_id = customers.id
WHERE placed = '2026-01-20';Returns
| id | customer_id | product_id | quantity | placed | id | name | city | age |
|---|---|---|---|---|---|---|---|---|
| 12 | 2 | 6 | 1 | 2026-01-20 | 2 | Luke | Austin | 27 |
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. Find the bug
This query should give the warehouse its list: the order number and the name of whoever is waiting for it, for the orders from January 15. Here SQL answers
ambiguous column nameand points atid. It means "there's more than one column with that name and I don't know which one you want." Which line has the problem?2. Predict the output
There was a single order on January 14, number 9, and it was placed by Dylan, who is customer 6. What does this query return?
3. Complete the code
At the warehouse they're holding the package for order 6. Whose is it, and which city is it going to? Fill in the filter.
4. Multiple choice
The alias
ois declared in theFROM, and theSELECT, one line above, already uses it. Why does that work?5. Complete the code
What has Dylan, customer 6, ordered? Fill in the alias the table is missing.
6. Predict the output
Luke is customer 2, and his orders are 3, 6, and 12. Order number 2 is Ann's. What does this query return?
7. Find the bug
Who ordered Headphones, which are product 7, and on what day? Someone started putting aliases in this query and left a line half done. Here SQL answers
no such columnand points atcustomers.name, even though thecustomerstable does have anamecolumn. Which line has the problem?8. Put the lines in order
The store's first four orders, the ones from before January 10. Put in order the query that shows each one's number, product, and quantity, from last to first. Two lines don't belong.
9. Multiple choice
This query runs today, with two columns written without their table. Which of these changes to the database would make it stop running tomorrow?
10. Put the lines in order
For the orders from January 14 on, the warehouse wants the order number and the customer number, each under a heading that says which it is, plus the name. Put the query in order, with the rows by customer number and, within each customer, by order number. Two lines don't belong.
11. Write the code
The orders from January 12 on are still to be delivered. Write the shipping list, a query with three columns: the order number, then the name of whoever receives it, then their city, which should say
unconfirmedwhere it's missing. Sort the rows by name, and one person's packages by order number.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.