SELECT Class,STUFF( ( SELECT ','+ Name FROM a b WHERE b.Class = a.Class FOR XML PATH('')),1 ,1, '') NameFROM a a GROUP BY Class