All problems

Students Enrolled in Machine Learning

mediumSQLJoins

Fairhaven University's IT desk creates GPU accounts by hand, one for each student taking the Machine Learning course. They have asked for the names of those students — names, not id numbers, because the accounts are cut against university logins.

Nothing links a student to a course directly. A registration table sits between the two, holding a pair of id numbers per registration and no titles or names at all. So the course you care about is identified by its title in one table and by a bare number in the middle one, and the student by a different bare number on the other side of it.

students — one row per student. gpa is on the usual 0–4 scale.

id name major gpa
1 Nora Fischer Computer Science 3.8
2 Omar Haddad Statistics 3.4
3 Petra Novakova Computer Science 3.9
4 Quinn Walsh Mathematics 3.1
5 Ravi Shah Statistics 3.6

courses — one row per course on offer. credits is how many credits it carries.

id title credits
1 Intro to Databases 3
2 Machine Learning 4
3 Linear Algebra 3
4 Data Visualization 2

enrollments — one row per student-course registration. grade is NULL if the work is not yet marked.

student_id course_id grade semester
1 1 3.7 Fall2023
1 2 3.9 Spring2024
2 1 3.2 Fall2023
2 3 3.5 Fall2023
3 2 4.0 Spring2024
3 4 3.8 Spring2024
4 3 2.9 Fall2023
5 1 3.6 Fall2023
5 2 NULL Spring2024

All three tables already exist in the database — there is nothing to create or load.

Task: Write a query returning a single column, name, listing every student registered for the course titled "Machine Learning", sorted alphabetically by name.

Example output — shape only, on invented names.

name
Kofi Mensah
Lucia Ferreira
Tara Villalobos

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…