We have a Student table with SubjectId. Here the requirement is to concatenate based on subjectId.
All SQL Server versions
create table #yourstudent (subjectid int, studentname varchar(10))
insert into #yourstudent (subjectid, studentname) values
( 1 ,'Mary' )
,( 1 ,'John' ...