Students and Their Subjects
Problem statement
Join Students, StudentSubjects, and Subjects to list the subjects studied by each enrolled student. Return student_id, student_name, and subject_name, with one row per enrollment.
Students with no enrollment do not appear. Different subjects with the same name still produce separate rows.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
Students
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | — |
| name | Text | No | — |
Subjects
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | — |
| name | Text | No | — |
StudentSubjects
| Column | Type | Nullable | Description |
|---|---|---|---|
| student_idPK | Integer | No | — |
| subject_idPK | Integer | No | — |
Foreign key: student_id → Students(id)
Foreign key: subject_id → Subjects(id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| student_id | Integer | No | — |
| student_name | Text | No | — |
| subject_name | Text | No | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
- The practice schema uses Students(id, name), Subjects(id, name), and StudentSubjects(student_id, subject_id). IDs are positive integers.
- Each student-subject pair is unique and references existing rows. Names are non-null, at most 100 characters, and need not be unique.
- Each table has at most 2000 rows. Empty tables are allowed. Output rows may be in any order.