I have 3 tables , adjustinlines , Items and itemmovement What i'm looking for is that i need to select from the tables : all the lines in the adjustinline with the description from the item table with the onhand quantity which is from the itemmovement table sum(qty)-sum(qtyout) group by itemid and warehouseid.
adjustinlines
itemid warehouseid adjustbyquantity
1 2 5
1 1 3
2 2 4
3 1 5
Items
Id description
1 Item 1
2 Item 2
3 Item 3
Itemmovement
itemid warehouseid qtyin qtyout
1 1 3
1 1 2
1 2 3
1 2 1
2 2 1
Request View
Description warehouseid Onhandqty Adjustbyqty
Item 1 2 2 5
Item 1 1 1 3
Item 2 2 1 4
Item 3 1 0 5
I'm trying to use those 2 ways but both of them isn't giving me the correct result
SELECT sum(itemv.qtyin) sum(itemv.qtyout),adjo.warehouseid,adjo.itemid,
adjo.adjustbyquantity,itm.description
FROM adjustoutcopy adjo
LEFT JOIN itemmovement AS itemv
ON adjo.itemid=itemv.itemid AND
adjo.warehouseid=itemv.warehouseid
LEFT JOIN items AS itm
ON adjo.itemid=itm.Id
group by itemv.itemid,itemv.warehouseid
ORDER BY adjo.Id DESC
If the itemid doesn't exist in the itemmovement table , the line isn't being appeared , as the code is using the join Inner .