In order to be on the safe side, you should create 3 queries:
query1 contains Common.SKU & SUM(Table1.qty), Grouped.
query2 contains Common.SKU & SUM(Table2.Qty2), Grouped.
query 3 contains Common.SKU, Sum(qty) from query1 and Sum(Qty2) from query 2, both queries joined on SKU
Sounds messy, but should do fine.
MakeItSo
Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
You could include the Common table in query3, select common.sku and create left joins from your queries to the common table on SKU (display all from query and only those from table matching)
qrySku:
Select Distinct SKU From Table1
Union
Select Distinct SKU From Table2
Select qrySku.SKU, Sum(Table1.qty), Sum(Table2.qty2)
From qrySku (Left Join Table1 On qrySku.SKU = Table1.SKU) (Left Join Table2 On qrySku.SKU = Table2.SKU)
Group By qrySku.SKU
The syntax of the join statements may not be perfect but you should get what you want. qrySku gives you a list of all of the SKU values from both tables and the outer joins allow you to retrieve all of the SKU values even when that value does not appear in one or the other table.
Select DISTINCT A.SKU,
(Select SUM(X.Qty) From Table1 X
Where X.SKU = A.SKU) As SumQty,
(Select SUM(X.Qty2) From Table2 X
Where X.SKU = A.SKU) As SumQty2
From Common As A
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.