AnalystPath

Each Member's First Gym Visit

SQLEasyJunior level~15 min

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.

visits
member_idbranch_idvisit_dateminutes
122021-01-1045
122021-02-0460
232021-03-2230

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

Related SQL questions