id | name
id | name
id | student_id | class_id
id | name | classes
1 | Bob | Class 1, Class 2
2 | Sara | Class 2
3 | Jon | -
SELECT s.id, s.name, GROUP_CONCAT(DISTINCT c.name SEPARATOR ', ') as classes
FROM students s
LEFT JOIN student_classes sc ON sc.student_id = s.id
LEFT JOIN classes c ON c.id = sc.class_id
GROUP BY s.name
ORDER BY s.id ASC;