Home / SQL / Practice problems / Medium

Orders with 3 or more products

Medium

Show the order_id and the number of different products of orders containing at least 3 different products.

Tables: customers(customer_id, name, city, country, joined) · products(product_id, name, category, price) · orders(order_id, customer_id, order_date, status) · order_items(order_id, product_id, quantity, unit_price)

Your query
Show the expected result
order_idproducts
24
33
43
64
84
94
103
124
154
164
233
273
294
333
363
414
423
453
494
513

20 rows

Show a solution
SELECT order_id, COUNT(*) AS products FROM order_items GROUP BY order_id HAVING COUNT(*) >= 3;

SQL used

New to SQL? The free SQL course teaches everything these problems use, with a self-checking exercise in every lesson.