user860067
user860067

Reputation: 121

Combining result sets into array in SQL query

Let's say i have this table

Col-A     Col B 
  1         2
  1         3
  1         5
  2         1
  2         2
  2         8

And i want a query to return a result set built out of Col-A & an array of all Col-B value.

Meaning a select that will return for this specific table:
Record1: 1,[2,3,5]
Record2: 2,[1,2,8]

Is this achievable?

Thanks.

Upvotes: 4

Views: 482

Answers (1)

Benoit
Benoit

Reputation: 79185

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;

Upvotes: 2

Related Questions