Find Unique Course Enrollments
UptoSkills Arena needs to identify all the unique courses available for enrollment by students. This information is crucial for curriculum planning and resource allocation.
Tables:
Enrollments(enrollment_idINT PRIMARY KEY,student_idINT,course_idINT)
Return a single column containing the course_id of each unique course a student has enrolled in. The order of the results does not matter, but NULL course IDs should be excluded.
Handling NULLs and Empty Results:
- Rows where
course_idis NULL should not be included in the output. - If no enrollments exist or all
course_ids are NULL, an empty result set should be returned.
Tables
CREATE TABLE Enrollments (
enrollment_id SERIAL PRIMARY KEY,
student_id INTEGER NOT NULL,
course_id INTEGER
);Example data
INSERT INTO Enrollments (student_id, course_id) VALUES (101, 1001), (102, 1002), (103, 1001), (104, 1003), (105, 1002), (106, NULL), (107, 1001), (108, 1004);
Your query is also checked on hidden datasets with different data.
Hints
-- Select the unique course IDs
SELECT course_id
FROM Enrollments
Your query runs on the example tables shown with the problem, then on hidden datasets when you submit.
Write standard SQL. MySQL habits work too: IFNULL, IF, YEAR(), DATE_FORMAT, GROUP_CONCAT, `backticks` and LIMIT 5, 10. It runs on PostgreSQL, so integer division keeps whole numbers (5 / 2 = 2): write 5.0 / 2 for 2.5.