Combining result sets into an array in an SQL query

Let's say I have this table

  Col-A Col B 
   12
   13
   fifteen
   2 1
   2 2
   2 8

And I want the query to return a result set built from Col-A and an array of all Col-B values.

The selection value that will be returned for this particular table:
Record 1: 1, [2,3,5]
Record 2: 2, [1,2,8]

Is this achievable?

Thanks.

+4
source share
1 answer

Depending on your DBMS:

Oracle: SELECT col_a, WMSYS.WM_CONCAT(col_b) FROM my_table GROUP BY col_a;

SQLite: SELECT col_a, group_concat(col_b, ',') FROM my_table GROUP BY col_a;

+2
source

All Articles