Please help me with sql query to fullfill below requirement
I want to join a table with another table having a JSON column with two string column comparison.
This query is for Azure SQL DB i want to join Table 2 with Table 1
where it should satisfy below 2 conditions Table2.Items(each item).product_category = Table1.product_category and Table2.Items(each item).product_id = Table1.product_id
and want to get all items and columns in Table two with expanding each item in JSON items to rows
Table 1
product_category product_name product_id product_cost
Gift Glass 157 85
Electronics Bulb 833 218
Kitchen Glass 157 75
Table 2
Order_ID Pincode Order_details Email
HASDUI2N342 766815 <JSON_Data> user1@domain.com
ASDIJ234HJI 487957 <JSON_Data> user2@domain.com
ASDOI23480H 512878 <JSON_Data> user2@domain.com
Sample <JSON_Data>
for order_id HASDUI2N342
{
"order_date": "26-07-2019",
"Items": [
{
"product_category": "Gift",
"product_id": "157"
},
{
"product_category": "Electronics",
"product_id": "833"
}
],
"amount_paid": 333,
"shipping" : 30
}
Below is the excpect Result Table after joinning both
Order_ID Pincode Email Item.product_Name Item.product_cost
HASDUI2N342 766815 user1@domain.com Glass 85
HASDUI2N342 766815 user1@domain.com Bulb 218
ASDIJ234HJI 487957 user2@domain.com ..... ....
ASDIJ234HJI 487957 user2@domain.com ..... ....
ASDOI23480H 512878 user3@domain.com ..... ....