Students Taking Biology
Return student_id for every student with an enrollment in any section of the course whose code is 'SCI301'. Each student once. Sort by student_id.
Hint 1
Work from the inside out: the sections of SCI301, then the enrollments in those sections.
Reference solution
SELECT DISTINCT student_id
FROM enrollments
WHERE section_id IN (
SELECT s.section_id
FROM sections AS s
JOIN courses AS c ON c.course_id = s.course_id
WHERE c.code = 'SCI301'
)
ORDER BY student_id;
IN (subquery) keeps the rows whose value is in the list the subquery returns. The list can contain repeated values (harmless), but the outer query returns one row per enrollment, so a student with two SCI301 sections shows up twice unless you add DISTINCT. A join solves the same problem; use whichever reads more clearly.
Another way. The same result with joins and DISTINCT.
SELECT DISTINCT e.student_id
FROM enrollments AS e
JOIN sections AS s ON s.section_id = e.section_id
JOIN courses AS c ON c.course_id = s.course_id
WHERE c.code = 'SCI301'
ORDER BY e.student_id;