I built a Union query in Access that takes results from two separate queries and joins them together. It's working fine but the results are not being grouped by Sales, Cost, and Profit, where I am trying to sum on those three fields.
Here is my code:
SELECT
Store,
count( [MASTER CREDIT MEMO QUERY].[Count]) as Count,
[Sales Code],
Name,
Sum( [MASTER CREDIT MEMO QUERY].[Sales]) as Sales,
Sum( [MASTER CREDIT MEMO QUERY].[Cost]) as Cost,
Sum( [MASTER CREDIT MEMO QUERY].[Profit]) as Profit
FROM [MASTER CREDIT MEMO QUERY]
GROUP by
Store,
[Sales Code],
Name
UNION SELECT
Store,
count([MASTER SALES INVOICE QUERY].[Count]) as Count,
[Sales Code],
Name,
Sum([MASTER SALES INVOICE QUERY].[Sales]) as Sales,
Sum([MASTER SALES INVOICE QUERY].[Cost]) as Cost,
Sum([MASTER SALES INVOICE QUERY].[Profit]) as Profit
FROM [MASTER SALES INVOICE QUERY]
GROUP BY
Store,
[Sales Code],
Name
ORDER BY Sales DESC;
Can anyone help me get the grouping to work?