Skip to content

Get all record in each group using group by clause

I have a table like this

I want the result to be

and my query I can think of so far is:

But this one doesn’t work out because EmployeeName column is not in the Group By clause, the query will give the wrong result if I name that column in the Group By clause.

Could someone show me the way I can archive that result?

Advertisement

Answer

You can use use string_agg() :

For older version, you can do :

User contributions licensed under: CC BY-SA
9 People found this is helpful