AnalystPath

Course of Each Learner's First Enrollment

SQLEasyJunior level~15 min

Problem

An online learning platform logs each course a learner enrolled in, and when.

Table: `enrollments`

| Column | Type |
|---------------|------|
| learner_id | int |
| course_id | int |
| enroll_date | date |
| hours_studied | int |

`(learner_id, enroll_date)` is the primary key.

Write a query that reports, for each learner, the `course_id` they enrolled in on their **earliest** `enroll_date`. Return columns `learner_id` and `course_id`, in any order.

Tables

Example rows — the live problem includes the full dataset.

enrollments
learner_idcourse_idenroll_datehours_studied
1202023-01-055
1212023-03-026
2302023-02-181

Expected output

Your answer should return 3 rows with the columns learner_id, course_id.

Starter code (SQL)

SELECT *
FROM enrollments;

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