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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine queries with different items 1

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
330
GB
I have one query that contains sales of all items in a date range, and another that contains credits in the same date range.

Almost always the credits are for products for which there are corresponding sales. But sometimes not, where a customer has received credits for products bought earlier than the date range, and there have been no sales of these products in the current date range.

I can use a join type to subtract credits for all products where there have been sales but I'm looking for a way of including the data for credit-only products.

This shows an example of the two queries.
Sales_and_Credits_ogyslv.jpg


The highlighted credit is without corresponding sale product. The end result I need would start like this but I can only think of complicated ways of getting to this result.

Result_quthcq.jpg
 
I'm not sure what you are looking for. Do you want to include all sold and credit records if they exist in either list?

Can you share the SQL view of your queries?


Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
How about:

"the credits [...] for products for which there are corresponding sales."
UNION
"products bought earlier than the date range, and there have been no sales of these products in the current date range."
[ponder]


---- Andy

There is a great need for a sarcasm font.
 
Slightly expanding Andy's hint:
1. union query qryBeerSoldCreditDutyCalc:
[tt]SELECT [Beer Name], [ABV], [Pints] AS [Vol]
FROM
qryBeerSoldDutyCalc
UNION ALL
SELECT [Beer Name], [ABV], -[Pints] AS [Vol]
FROM
qryBeerCreditDutyCalc;[/tt]
2. aggregate query (sum) from qryBeerSoldCreditDutyCalc

combo
 
Thanks all for quick responses, Andy for the pointer but especially Combo for giving the complete solution, worked a treat. Had forgotten about Union queries, symptom of 8th decade.

Thanks to all too for previous advice on how to submit questions clearly, still learning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top