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✔ Solved
Show the expected result
| name | first_order |
|---|---|
| Aarav Sharma | 2025-02-27 |
| Mia Chen | 2025-12-10 |
| Liam Walker | 2025-07-28 |
| Sita Gurung | 2025-06-05 |
| Priya Patel | 2025-10-05 |
| Olivia Smith | 2025-04-20 |
| Bikash Thapa | 2025-08-16 |
| Ava Wilson | 2025-03-12 |
| Ethan Nguyen | 2025-04-26 |
| Isla Taylor | 2025-04-16 |
| Lucas Martin | 2025-02-24 |
| Zoe Clarke | 2025-03-02 |
| Hiroshi Tanaka | 2025-01-08 |
| Grace Lee | 2025-02-07 |
| Jack Murphy | 2025-03-22 |
| Leo Rossi | 2025-05-02 |
| Chloe Davies | 2025-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.