I have a table like so –
x
id_sale name
20029 Robert
10029 Christine
10029 Deborah
How do I output this result –
id_sale name
20029 Robert
10029 Christine, Deborah
Advertisement
Answer
For an array, you would use array_agg()
:
select id_sale, array_agg(name)
from t
group by id_sale;
If you want the value as a comma-sseparated string:
string_agg(name, ', ')