Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

First Product Purchased Per Customer

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is First Product Purchased Per Customer. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Write a PostgreSQL query to find the first product each customer purchased on the Apidel Technologies platform. Return the customer, the first order, its timestamp, and the product name. If two orders share the same earliest timestamp for a customer, use the smaller order_id as the tie-breaker.

Schema

customers
ColumnTypeDescription
customer_idINTPrimary key
customer_nameVARCHAR(100)Customer name
orders
ColumnTypeDescription
order_idINTPrimary key
customer_idINTCustomer reference
product_idINTProduct reference
purchased_atTIMESTAMPPurchase timestamp
products
ColumnTypeDescription
product_idINTPrimary key
product_nameVARCHAR(100)Product name
Tablescustomersordersproducts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results