Code of the Day
IntermediateCombining data

Lab: combining data

Join tables, aggregate across them, and filter with a subquery — checked instantly.

Lab · optionalSQLIntermediate20 min
Recommended first
By the end of this lesson you will be able to:
  • 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

Each order with its customer

Return the customer name and order date for every order (two columns). Join orders to customers.

Checkpoint 2 — aggregate over a join

Total quantity sold per product

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

Customers who have ordered

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.

Finished reading? Mark it complete to track your progress.

On this page