I'm trying to get 2 sums from my tables, one is a table of ordered items and another is a table of received items. With my current query i'm getting a sum of 2014 which is from 106(the actual sum I want to get) multiplied by 19(the number of records)
select POD.PO_No, SUM(POD.Qty) as Qty, RRD.RR_No, SUM(RRD.QtyRcvd) as QtyReceived
from tbl_PODetail POD inner join tbl_RRDetail RRD on POD.PO_No = RRD.PO_Reference
where POD.PO_No = 'PO-000001'
group by POD.PO_No, RRD.RR_No
What causes this and how can I correct it?
Sample Table
PO No | Item | Qty
-------------------------
PO-0000001 | Item A | 5
PO-0000001 | Item B | 7
PO-0000001 | Item B | 3
RR No | Item | Qty | PO_Reference
----------------------------------------
RR-0000001 | Item A | 5 | PO-0000001
RR-0000001 | Item B | 7 | PO-0000001
RR-0000001 | Item B | 3 | PO-0000001
Expected Output:
PO No | Qty | RR No | Qty Rcvd
-----------------------------------------
PO-0000001 | 15 | RR-0000001 | 15
What I get
PO No | Qty | RR No | Qty Rcvd
-----------------------------------------
PO-0000001 | 45 | RR-0000001 | 45