Hi I have a table like so
| orderId | productId |
|---|---|
| 1 | 23 |
| 1 | 24 |
| 1 | 27 |
| 2 | 25 |
| 2 | 26 |
| 3 | 27 |
and want to transform it into
| orderId | productIds |
|---|---|
| 1 | 23,24,27 |
| 2 | 25,26 |
| 3 | 27 |
How do I achieve this?
>Solution :
Use STRING_AGG:
SELECT orderId, STRING_AGG(productId ORDER BY productId) AS productIds
FROM yourTable
ORDER BY orderId;