Database Column:
inquiry.productdescription=[
{"productkey":"yrty","productvalue":"700*600","quantity":"5","note":"round"},
{"productkey":"c","productvalue":"600*4000","quantity":"1000","note":"notess"},
{"productkey":"rtyrty","productvalue":"600*900","quantity":"3","note":"tertert"}
]
providerinqlog.price_json=["70","30","60"]
providerinqlog.time_json=["3 mons","200","4 week"]
suppose in above example, '{"productkey":"c", "productvalue":"600*4000"}' matches with 1st position of inquiry.productdescription so get the data of 1st position of providerinqlog.price_json and providerinqlog.time_json like here I should get 30 in price_json and 200 in time_json
SELECT * FROM inquiry
JOIN providerinqlog ON providerinqlog.inquiry_id =inquiry.id
WHERE JSON_CONTAINS(inquiry.productdescription,
'{"productkey":"c", "productvalue":"600*4000"}')
AND inquiry.userid=128
and inquiry.id!=320
and providerinqlog.provider_id=159
and (providerinqlog.status_inq=2 OR providerinqlog.status_inq=3);
I tried this query but i am getting all data with price_json as ["70","30","60"] and time_json as ["3 mons","200","4 week"]
Here's a solution, tested on MySQL 8.0 or later.
Demo: https://dbfiddle.uk/Z77qGoRD
This is made more complicated than it should be because you store data in JSON instead of normal rows and columns. If you used a normal relational database design, it should look something like this:
This does not use JSON. Each array item in your
inqirytable should be a separate row in a second table which I have calledinquiry_productin this example. Each field of the JSON object should be in its own column.There is no reason given your example that you should be using JSON. It doesn't save anything, in fact it uses more storage. It makes queries more complicated and difficult.