0

Say for example I have the following in a table:

grouping user_id
A abcdefg
B 123456
A hijklmn
A opqrstu
B 789012
C ...

The result I would like to SELECT in a single query is:

grouping user_id
A abcdefg, hijklmn, opqrstu
B 123456, 789012
C ...

... and so on as far as there is a unique 'grouping' and the user_ids found under those groupings.

Is it possible to do this in a single query?

I have done some research of my own and seen syntax such as XML, CONCAT and others but as far as I can tell those answers do not account for multiple lists and multiple groupings.

KeHo
  • 1
  • 1
  • 1
    I believe you want [`LISTAGG()`](https://docs.aws.amazon.com/redshift/latest/dg/r_LISTAGG.html). `SELECT grouping, LISTAGG(user_id) FROM yourtable GROUP BY grouping;` – JNevill Nov 01 '22 at 18:17

0 Answers0