I have a column ordersdetail with type JSON in my mysql table orderAnalysis with below example.
first row
{ "id": 123, "items": [ { "id": 1623364501551, "product_id": 11931258628 }, { "id": 1623364534319, "product_id": 11931258630 }] }
second row
{ "id": 124, "items": [ { "id": 1623364501552, "product_id": 11931258629 }, { "id": 1623364534320, "product_id": 11931258632 }] }
I want to get row data if any product_id matched with given id from array of items. I have done R&D for it and got some solutions and when I tried that solutions none of thems didn't worked in my case.
I am tried using these queries as below:-
#first query
SELECT ordersdetail FROM `orderAnalysis` WHERE JSON_SEARCH(ordersdetail->>'$.items[*].product_id', 'one', 11931258628)
#second query
SELECT ordersdetail FROM `orderAnalysis` WHERE ordersdetail->"$.items[*].product_id" = 11931258628
#third query
SELECT ordersdetail FROM `orderAnalysis` WHERE json_extract(ordersdetail, '$.items[*].product_id') = 11931258628
But these queries not helped me to get result. I want first row as output in result. Please help me.
Thanx in advance
JSON_SEARCHonly works on string values. See the duplicate...