0
Col1 Col2
_________
A   |  1
A   |  2
A   |  3
B   |  4
B   |  5
B   |  6

and i need to obtain something like this

col1 list
________
A   | 1,2,3
B   | 4,5,6

i'm still beginner give me the most simple alternative

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843

1 Answers1

1

Try the following with array_agg

select
    col1,
    array_agg(col2)
from yourTable
group by
    col1

or with string_agg

select
    col1,
    string_agg(col2, ', ')
from yourTable
group by
    col1
zealous
  • 7,088
  • 3
  • 11
  • 35