Skip to content
Advertisement

How to search JSON array field in MySQL?

I have a column which has json type arrays like

row1: ["abc", 10, null, true, false]
row2: ["def", 10, null, true, false]

How can i use where clause to find "abc" contained rows? My json arrays has no key. They only have values.

select * from myTable where JSON_SEARCH(myColumn,"all","abc")

returns 0 rows

Advertisement

Answer

You can use MySQL JSON search function JSON_CONTAINS():

where json_contains(myColumn, '"abc"')
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement