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.

1
  • 1
    It's very counter-intuitive to use "row1" as column name. Commented Feb 3, 2015 at 3:39

1 Answer 1

4

Use String_agg function

SELECT row1, row2, string_agg(row3, ',') as row3 FROM your_table GROUP BY row1, row2 
Sign up to request clarification or add additional context in comments.

1 Comment

Great, thanks. This did the trick. Also found this for anyone else needing this answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.