Home / SQL / Practice problems / Medium

Each customer's first order

Medium

Show each customer's name and the date of their first_order, for customers who have ordered.

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
namefirst_order
Aarav Sharma2025-02-27
Mia Chen2025-12-10
Liam Walker2025-07-28
Sita Gurung2025-06-05
Priya Patel2025-10-05
Olivia Smith2025-04-20
Bikash Thapa2025-08-16
Ava Wilson2025-03-12
Ethan Nguyen2025-04-26
Isla Taylor2025-04-16
Lucas Martin2025-02-24
Zoe Clarke2025-03-02
Hiroshi Tanaka2025-01-08
Grace Lee2025-02-07
Jack Murphy2025-03-22
Leo Rossi2025-05-02
Chloe Davies2025-04-03

17 rows

Show a solution
SELECT c.name, MIN(o.order_date) AS first_order FROM customers c JOIN orders o ON o.customer_id = c.customer_id GROUP BY c.customer_id;

SQL used

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