Menu
Coddy logo textTech

Recap - Join

Part of the Fundamentals section of Coddy's SQL journey. Lesson 45 of 72.

challenge icon

Challenge

Medium

Available tables and columns:

  • orders: id, customer_id
  • products: id, unit_price, units_in_stock
  • order_items: id, order_id, product_id, quantity

Find the customer IDs of customers who have ordered products with a unit price less than 10, and list the total quantity of those cheap products each customer has ordered.

Return following columns:

  • customer_id
  • total_quantity (the sum of quantities of products with a unit price < 10 for each customer)

Try it yourself

-- List the grouping column and the aggregated value the task asks for
SELECT ____
FROM orders
-- Each join needs a condition matching an id column to the column that points at it
INNER JOIN order_items ON ____
INNER JOIN products ON ____
-- Then keep only the rows that meet the threshold the task describes
WHERE ____
GROUP BY orders.customer_id;

All lessons in Fundamentals

Practice on your own: SQL playground