AnalystPath

Enrollments in Missing Courses

SQLEasyJunior level~15 min

Problem

Table: `Course`

```text
+-----------+---------+
| Column | Type |
+-----------+---------+
| course_id | int |
| label | varchar |
+-----------+---------+
course_id is the primary key. Each row is a course offered by the academy.
```

Table: `Enrollment`

```text
+------------+---------+
| Column | Type |
+------------+---------+
| enroll_id | int |
| learner | varchar |
| course_id | int |
+------------+---------+
enroll_id is the primary key. course_id should reference a real course, but
because of a data-entry bug some enrollments point at a course_id that does
not exist in the Course table.
```

Report every enrollment whose `course_id` does **not** appear in the `Course` table. Return `enroll_id` and `learner`. Rows may be in any order.

**Example**

```text
Course:
+-----------+---------+
| course_id | label |
+-----------+---------+
| 1 | Algebra |
| 2 | Optics |
+-----------+---------+

Enrollment:
+-----------+---------+-----------+
| enroll_id | learner | course_id |
+-----------+---------+-----------+
| 100 | Priya | 1 |
| 101 | Marcus | 9 |
| 102 | Lena | 2 |
+-----------+---------+-----------+

Output:
+-----------+---------+
| enroll_id | learner |
+-----------+---------+
| 101 | Marcus |
+-----------+---------+
```

Enrollment 101 points at course 9, which has no matching row in Course, so it is the only invalid enrollment.

Tables

Example rows — the live problem includes the full dataset.

Course
course_idlabel
1Algebra
2Optics
Enrollment
enroll_idlearnercourse_id
100Priya1
101Marcus9
102Lena2

Expected output

Your answer should return 1 row with the columns enroll_id, learner.

Starter code (SQL)

SELECT *
FROM Course;

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