1

This question has probably been answered and I have found part of the solution here for Postgres.

I am running version 9.1 of Postgres and this is what I am trying to do.
I have a table:

 col1 |   col2    | col
------------------------
  1   | 1 jan 12  | Joe
  1   | 1 jan 12  | Bill
  1   | 1 jan 12  | Sue
  2   | 2 may 13  | Bob
  2   | 2 may 13  | Mary

I want:

 col1 |   col2    | col3
------------------------
  1   | 1 jan 12  | Joe, Bill, Sue
  2   | 2 may 13  | Bob, Mary

I am sure the solution is simple, I just have not been able to come up with it despite searching. I am guessing that array_agg is probably part of my solution.

Community
  • 1
  • 1
Mikolaj
  • 688
  • 8
  • 19

1 Answers1

4

Use String_agg function

SELECT row1,
       row2, 
       string_agg(row3, ',') as row3
FROM your_table
GROUP BY row1,
         row2
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172
  • Great, thanks. This did the trick. Also found [this](http://stackoverflow.com/a/12365699/4442529) for anyone else needing this answer. – Mikolaj Feb 03 '15 at 02:20