Find Unique Course EnrollmentsEasy

Find Unique Course Enrollments

EasySQLPractice library · +10 XPdistinct valuessqlenrollments

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_id INT PRIMARY KEY, student_id INT, course_id INT)

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_id is 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