randomjohnny
randomjohnny

Reputation: 13

MariaDB: how to join to another table on JSON array's element's field and selecting a value from the other table for each array element

I have two tables, for example's sake I simplified it:

Table A

id data
1 [ { "b_id": 1 }, { "b_id": 2 } ]
2 [ { "b_id": 2 }, { "b_id": 3 } ]
3 NULL

Table B

id name
1 random
2 foo
3 bar

I would like to select the data column from Table A but with each json array element including the corresponding name from Table B, so the result would look something like this

SELECt ... FROM TableA LEFT JOIN TableB ON ...
data
[ { "b_id": 1, "b_name": "random" }, { "b_id": 2, "b_name": "foo" } ]
[ { "b_id": 2, "b_name": "foo" }, { "b_id": 3, "b_name": "bar" } ]
NULL

Edit: MariaDB version: 11.2.2-MariaDB-1:11.2.2+maria~ubu2004-log

Upvotes: 0

Views: 88

Answers (0)

Related Questions