mysql - Issue with sql query to get the results -
i having problem sql query. how table structure looks like.
the scenario there order details in order table(initially shipping details id null) , ordered items saved accordingly. when dispatching orders driver can select 1 or more orders. assume if selects 2 orders('cc0-c1b-50b-63b' , 'fb2-fc6-57b-dd8') new record added shipping_details table(so no of places 2 in our case) , 2 records saved accordingly in delivery_place table.
what want : if select order no 'cc0-c1b-50b-63b', want delivery orders(in our case there order 'fb2-fc6-57b-dd8'and result should 2 orders) , departmentid in orderd_items table 2 orders. (if there multiple items in single order, items in same department)
so tried query,
select oi.fkorderid,dp.deliveryplaceid,dp.fkshippingdetailsid,dp.city,dp.position,oi.fkdepartmentid `order` o join `shipping_details` sd on o.fkshippingdetailsid = sd.shippingdetailsid join `ordered_items` oi on o.orderid = oi.fkorderid join `delivery_places` dp on dp.fkshippingdetailsid=sd.shippingdetailsid o.orderid = 'cc0-c1b-50b-63b' group dp.deliveryplaceid order dp.position asc ;
and result this,
but second row should 'fb2-fc6-57b-dd8' fkorderid , '11' fkdepartmentid.
this data table
updated input data
order table
shipping details table
ordered_items table (columns: ordereditemsid , fkitemid , quantity , size, fkdepartmentid , fkorderid)
department table
so how modify query result?
thanks.
this how achieved result ,
select distinct(oi.fkorderid),dp.deliveryplaceid,dp.fkshippingdetailsid,dp.city,dp.longitude,dp.latitude,dp.timestamp,dp.position,dp.status,o.orderstatus,oi.fkdepartmentid `ordered_items` oi, `order` o join `shipping_details` sd on o.fkshippingdetailsid = sd.shippingdetailsid join `delivery_places` dp on dp.fkshippingdetailsid=sd.shippingdetailsid o.orderid = 'cc0-c1b-50b-63b' , oi.fkorderid in (select orderid `order` fkshippingdetailsid=o.fkshippingdetailsid) group oi.fkorderid order dp.position asc
and here result,
Comments
Post a Comment