Answer the question
In order to leave comments, you need to log in
How to query a nested json array in MySQL?
Hello!
There is a json that is written in the data_json field with type "json" in a MySQL table:
{
"name": "Test",
"books": [
{
"id": 1
},
{
"id": 2
}
]
}
SELECT
*
FROM
test
WHERE
data_json -> "$.books[*].id" = 1
Answer the question
In order to leave comments, you need to log in
Not at all, or I don't know how.
The fact is that the selection data_json -> "$.books[*].id" will return such a value "[1, 2]" it is incorrect to compare it with a number.
MySQL 8 has JSON_TABLE , I assume that from "[1, 2]" you can make a table and build a condition on it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question