Is There a GROUP BY Aggregate that lists all the values

I am working on a calculated field. Is there an Group By aggregate that will list all the values in the group into one field.

Example, I want this:

Name Food
John Apple
John Banana
John Orange
John Tomatoe
Mary Banana
Mary Beans
Mary Kiwi
Joe Orange
Joe Banana

To be this:

Name Food
John Apple, Banana, Orange, Tomatoe
Mary Banana, Beans, Kiwi
Joe Orange, Banana

Something like SELECT GroupName, STRING_AGG(Name, ', ') AS Departments
FROM HumanResources.Department
GROUP BY GroupName;

2 Likes

Using pivot you can get them in one row.