Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COMBINE SQL 2

Status
Not open for further replies.

johnny45

Technical User
Nov 8, 2006
136
CA
Hello
using the following query to get qty SOLD for 2009:
Code:
SELECT OEINVD.ITEM, Sum(OEINVD.QTYSHIPPED) AS SUMSOLD
FROM OEINVH INNER JOIN OEINVD ON OEINVH.INVUNIQ = OEINVD.INVUNIQ
GROUP BY OEINVD.ITEM, OEINVH.INVFISCYR
HAVING (((OEINVH.INVFISCYR)="2009"));

and the following to get RETURNS for 2009:
Code:
SELECT OECRDD.ITEM, SUM(OECRDD.QTYRETURN) AS RETURNS
FROM OECRDH INNER JOIN OECRDD ON OECRDH.CRDUNIQ = OECRDD.CRDUNIQ
WHERE (((OECRDH.INVFISCYR)="2009"))
GROUP BY OECRDD.ITEM

my question, ca these 2 qyeries be combined into one to get the NET (SOLD less RETURNS) by ITEM ????
 
Why beat yourself to death?

Code:
SELECT OESHDT.ITEM, Sum(OESHDT.QTYSOLD) AS SumSOLD
FROM OESHDT
GROUP BY OESHDT.ITEM, OESHDT.YR
HAVING OESHDT.YR="2009";
 
You can also use

Code:
SELECT OESHHD.ITEM, Sum(OESHHD.QTYSOLD) AS SumSOLD
FROM OESHHD
WHERE OESHHD.YR="2009"
GROUP BY OESHHD.ITEM;
 
Thank you both for demystifying the accpac tables for me.

Cheers,
Johnny
 
But just to answer your first question you would use the UNION or UNION ALL sql command. That will let you combine the results of two or more queries together.

The workarounds presented, however, are far better than using a UNION.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top