Each Member's First Gym Visit
Problem
A gym records every visit by its members.
Table: `visits`
| Column | Type |
|-------------|------|
| member_id | int |
| branch_id | int |
| visit_date | date |
| minutes | int |
`(member_id, visit_date)` is the primary key. Each row is one day a member checked in at some branch and trained for a number of minutes.
Write a query that finds the **first visit date** for each member. Return columns `member_id` and `first_visit`, in any order.
Tables
Example rows — the live problem includes the full dataset.
| member_id | branch_id | visit_date | minutes |
|---|---|---|---|
| 1 | 2 | 2021-01-10 | 45 |
| 1 | 2 | 2021-02-04 | 60 |
| 2 | 3 | 2021-03-22 | 30 |
Expected output
Your answer should return 3 rows with the columns member_id, first_visit.
Starter code (SQL)
SELECT *
FROM visits;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock