I've got two queries and a table that I want to combine:
- [Product Demand] (table)
- [NA Supply] (query)
- [EU Supply] (query)
These three have identical fields:
- Date
- Region
- Product
- Quantity
Although, I will say that on the supply queries, I force the Date
and Region
to be static values, while Product
and Quantity
are pulled from a table. For example:
SELECT
DateValue("12/1/2017") AS [Date],
"North America" AS [Region], <-- Would be "Europe" for [EU Supply]
[NA Inv Report].[Product],
[NA Inv Report].[Quantity]
FROM [NA Inv Report] <-- Would be "EU Inv Report" for [EU Supply]
WHERE ((([NA Inv Report].[Quantity])>0));
I then have a basic Union Query, called [uQuery: Combo]
:
SELECT
[Product Demand].[Date] AS [Date],
[Product Demand].[Region] AS [Region],
[Product Demand].[Product] AS [Product]
FROM [Product Demand]
UNION SELECT
[NA Supply].[Date] AS [Date],
[NA Supply].[Region] AS [Region],
[NA Supply].[Product] AS [Product]
FROM [NA Supply]
UNION SELECT
[EU Supply].[Date] AS [Date],
[EU Supply].[Region] AS [Region],
[EU Supply].[Product] AS [Product]
FROM [EU Supply];
Then, I pull that Union Query into a new query;
SELECT
[uQuery: Combo].Date,
[uQuery: Combo].Region,
[uQuery: Combo].Product
FROM [uQuery: Combo];
This shows everything!
But here's the confusing thing; if I LEFT JOIN Product Demand
, it still shows everything. BUT if I LEFT JOIN one of NA Supply
or EU Supply
, then it will filter the results to the added table. If I add BOTH supply tables, then it won't show any results.
SELECT
[uQuery: Combo].Date,
[uQuery: Combo].Region,
[uQuery: Combo].Product
FROM (([uQuery: Combo]
LEFT JOIN [Product Demand] ON <-- Adding just this will show everything
([uQuery: Combo].Product = [Product Demand].Product) AND
([uQuery: Combo].Region = [Product Demand].Region) AND
([uQuery: Combo].Date = [Product Demand].Date))
LEFT JOIN [NA Supply] ON <-- Adding this will only show matching results for [NA Supply]
([uQuery: Combo].Product = [NA Supply].Product) AND
([uQuery: Combo].Region = [NA Supply].Region) AND
([uQuery: Combo].Date = [NA Supply].Date))
LEFT JOIN [EU Supply] ON <-- Adding this will hide all results
([uQuery: Combo].Product = [EU Supply].Product) AND
([uQuery: Combo].Region = [EU Supply].Region) AND
([uQuery: Combo].Date = [EU Supply].Date);