I've 2 cols lets say id and values. I want to concatenate values grouped by id col. for eg. I've ID Values 1 a 1 b 2 a 2 b I need the output as ID Values 1 a,b 2 a,b
I've 2 cols lets say id and values. I want to concatenate values grouped by id col. for eg. I've ID Values 1 a 1 b 2 a 2 b I need the output as ID Values 1 a,b 2 a,b
You can use an array_agg followed by an array_join
select id, array_join(array_agg(values),',') from table group by 1
The array_agg will give you an array of all values with the same id, and the array_join will concatenate them into a string. See the docs.