I'm using MySQL 5.6.43 and trying to search through in JSON array in a table. My JSON in MySQL database is like this:
[
{
"Name": "AAA",
"CountryCode": "AFG",
"District": "Kabol",
"Population": 1780000
},
{
"Name": "BBB",
"CountryCode": "AFG",
"District": "Qandahar",
"Population": 237500
},
{
"Name": "CCC",
"CountryCode": "USD",
"District": "Qandahar",
"Population": 237500
}
]
I want to take the just AFG CountryCode's. So my result should be like this:
[
{
"Name": "AAA",
"CountryCode": "AFG",
"District": "Kabol",
"Population": 1780000
},
{
"Name": "BBB",
"CountryCode": "AFG",
"District": "Qandahar",
"Population": 237500
}
]
How can I achieve that?
fiddle
In MySQL 5.6 you must use string functions - JSON is not implemented in this version yet:
fiddle
If source array may contain more than 4 objects per value then expand
numssubquery.Restriction: Neither key nor value to be searched must contain a space.