I want to write a query to select all the records where the values in the properties of a JSON object match a given string. For example, let's say I have a table with a column for address, which is a JSON object. The address for the first record looks like this:
{
"addressLine": "123 fake road"
"city": "Buffalo"
"state": "New York"
}
And the address for the second record looks like this:
{
"addressLine": "123 fake road"
"city": "New Haven"
"state": "Connecticut"
}
Would it be possible to write a query given the word 'New’ that would return both records since the values of the JSON contains that string? Thanks!
You can use JSON_EXTRACT function:
SELECT * FROM Table WHERE json_extract(JsonColumn, '$.city') like 'New%'
Additional information
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments