How to search JSON array in MySQL?

后端 未结 8 907
生来不讨喜
生来不讨喜 2020-11-29 06:03

Let\'s say I have a JSON column named data in some MySQL table, and this column is a single array. So, for example, data may contain:

8条回答
  •  难免孤独
    2020-11-29 06:27

    I don't know if we found the solution. I found with MariaDB a way, to search path in a array. For example, in array [{"id":1}, {"id":2}], I want find path with id equal to 2.

    SELECT JSON_SEARCH('name_field', 'one', 2, null, '$[*].id')
    FROM name_table
    

    The result is:

    "$[1].id"
    

    The asterisk indicate searching the entire array

提交回复
热议问题