Home

Published

- 1 min read

postgresql concatenate multiple rows in group by

img of postgresql concatenate multiple rows in group by

The solution for this is noted below

postgresql concatenate multiple rows in group by

Solution

   SELECT col_a,
array_to_string(array_agg(distinct col_b),',') AS Actor
FROM Table1
GROUP BY col_a;

-- Result:
-- MOVIE	ACTOR
-- A		1,2,3
-- B		4

Try other methods by searching on the site. That is if this doesn’t work