Search code examples
mysqlmysql-5.7mysql-json

Search in Json in mysql 5.7


I want to search product id from JSON filed but I am not able to search from JSON filed. In JSON field value added in multilevel like the below image.

enter image description here

I am able to search data from other filed like

SELECT equip_id FROM ' . $table. ' where  JSON_CONTAINS(category,["1"])

enter image description here

I want to search product by productID, Please let me know how can I achieve this.

Below are the full image of my table enter image description here


Solution

  • I have created a temp table with the below data.

    enter image description here

    Output when I used below query for above collection

    select * from table_name where json_contains(product, '{"productID" : "1"}')
    

    enter image description here