MariaDB [test]> select a, b, (
|
-> select json_arrayagg(i)
|
-> from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t
|
-> )
|
-> from (select 1 a, 2 b union all select 3 a, 4 b) as t
|
-> order by a;
|
+---+---+------------------------------------------------------------------------------------------------------+
|
| a | b | (
|
select json_arrayagg(i)
|
from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t
|
) |
|
+---+---+------------------------------------------------------------------------------------------------------+
|
| 1 | 2 | [1,2] |
|
| 3 | 4 | [1,2] |
|
+---+---+------------------------------------------------------------------------------------------------------+
|
2 rows in set (0,001 sec)
|
|
MariaDB [test]> explain extended select a, b, ( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t ) from (select 1 a, 2 b union all select 3 a, 4 b) as t order by a;
|
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------+
|
| 1 | PRIMARY | <derived3> | ALL | NULL | NULL | NULL | NULL | 2 | 100.00 | Using filesort |
|
| 3 | DERIVED | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
|
| 4 | UNION | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
|
| 2 | SUBQUERY | t | ALL | NULL | NULL | NULL | NULL | 40 | 100.00 | Table function: json_table |
|
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------+
|
4 rows in set, 3 warnings (0,001 sec)
|
|
Note (Code 1276): Field or reference 't.a' of SELECT #2 was resolved in SELECT #1
|
Note (Code 1276): Field or reference 't.b' of SELECT #2 was resolved in SELECT #1
|
Note (Code 1003): /* select#1 */ select `t`.`a` AS `a`,`t`.`b` AS `b`,(/* select#2 */ select json_arrayagg(`t`.`i`) from JSON_TABLE(json_array(`t`.`a`,`t`.`b`), '$[*]' COLUMNS (`i` int(11) PATH '$')) `t`) AS `( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t )` from (/* select#3 */ select 1 AS `a`,2 AS `b` union all /* select#4 */ select 3 AS `a`,4 AS `b`) `t` order by `t`.`a`
|
|
MariaDB [test]> select a, b, ( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$') ) t where rand() is not null ) from (select 1 a, 2 b union all select 3 a, 4 b) as t order by a;
|
+---+---+--------------------------------------------------------------------------------------------------------------------------------+
|
| a | b | ( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$') ) t where rand() is not null ) |
|
+---+---+--------------------------------------------------------------------------------------------------------------------------------+
|
| 1 | 2 | [1,2] |
|
| 3 | 4 | [3,4] |
|
+---+---+--------------------------------------------------------------------------------------------------------------------------------+
|
2 rows in set (0,001 sec)
|
I've got a very similar (same) issue:
if you want to "join" JSON-Array's this is not very handy, but should work as follows:
);
LIMIT 50
but the first value is repeated for every row