I’ve got a mysql field that has a json entry for horse racing, I’ve simplified a sample entry here:
{
"age": "4",
"course": "Ascot",
"horses": [
{
"number": "6",
},
{
"number": "5",
},
{
"number": "2",
},
{
"number": "7",
},
{
"number": "9",
}
],
"id_race": "242723",
"canceled": "0",
"distance": "5f",
"finished": "0",
"finish_time": ""
}
The following works fine if I want the races that have ID 242719:
SELECT * FROM races WHERE json_unquote(data->'$.id_race') = 242719;
But I’m actually trying to select the entries with horses number 2. The following just returns nothing:
SELECT * FROM races WHERE json_extract(data,'$.horses.number') = 2
And neither does this:
SELECT * FROM singleRaceCards WHERE json_unquote(data->'$.horses.number') = 2;
I’ve really tried looking it up but nothing is working for me. What am I doing wrong?