Each Athlete's Best Event
Problem
A decathlon league records the points an athlete scored in each event they competed in.
Table: result
+-----------+------+
| Column | Type |
+-----------+------+
| athlete_id| int |
| event_id | int |
| points | int |
+-----------+------+
(athlete_id, event_id) is the primary key. Each row is the points an athlete earned in one event.
Write a solution to find, for each athlete, the event in which they scored their highest points, along with that points value. If an athlete's top points are tied across multiple events, pick the event with the smallest event_id. Return columns athlete_id, event_id, and points, ordered by athlete_id ascending.
Tables
Example rows — the live problem includes the full dataset.
| athlete_id | event_id | points |
|---|---|---|
| 2 | 2 | 95 |
| 2 | 3 | 95 |
| 1 | 1 | 90 |
Expected output
Your answer should return 3 rows with the columns athlete_id, event_id, points.
Starter code (SQL)
SELECT *
FROM result;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