Lab: combining data
Join tables, aggregate across them, and filter with a subquery — checked instantly.
- Join related tables to answer cross-table questions
- Aggregate over a join with GROUP BY
- Filter with a subquery
Optional lab. Three queries on the shop (customers, products,
orders, order_items). Hit Check to compare your result against the
correct one; use Run to see your output as you go.
Checkpoint 1 — join orders to customers
Return the customer name and order date for every order (two columns). Join orders to customers.
Checkpoint 2 — aggregate over a join
Return each product's name and the total quantity ordered across all orders (two columns). Join order_items to products and group by product.
Checkpoint 3 — filter with a subquery
Return the name of every customer who has placed at least one order. Use a subquery against the orders table.
Done?
Three greens and you can pull data from across the schema — the skill most real SQL work is built on. Next up (when authored): the Advanced tier on schema design, indexes, transactions, and window functions.