sql - MySQL query to search a field with JSON string -
this might simple enough basic sql or might need regexp i've hit brick wall.
my data stored in json string these 2 examples (each in 1 field):
[{"id":"2","value":["1","3"]},{"id":"3","value":["1","2"]}]
and:
[{"id":"3","value":["2"]},{"id":"3","value":["1","2","5"]}]
i want search values in between last brackets might consist of many numbers ["1","2","5"] or single on ["2"]
. beginning numbers correspond 2 categories - single "id":"2"
, "id":"3"
.
using %"2"%
simple of course matches everything. can query "id":"$var"
return each category use php filter through after have results, data can quite large , i'm sure it's easy sql guru.
i don't have option change format of field, has remain json.
any appreciated! thanks.
i think solved using this: and extra_fields regexp '(.*"id":"2".*)("\[.*"1".*\]")'
. it's more regular expressions mysql :p
comment: (i couldn't find comment button)
syntax becomes clearer when learn "extra_fields" name of column in table
Comments
Post a Comment