попробуйте следующее. Вот Демонстрация
MySQL
select
id,
name,
group_concat(subject order by subject SEPARATOR ', ') as subject
from table
group by
id,
name
SQLite - Как order by
не вариант внутри group_concat
, вы можете сделать что-то вроде следующего
select
id,
name,
group_concat(subject, ', ') as subject
from
(
select
id,
name,
subject
from student
order by
id, subject
)
group by
id, name