问题
I want to run a union query on qry_1 in C:\DB\DB1.mdb and qry_2 in C:\DB\DB2.mdb
All examples I have seen only show how to run a Union Query on query's in the same database, how can you do this when the query's are in different databases?
EDIT --- Grr, not quite displaying results like I was after. That shows each entry twice. Is there a way to only show the entry one time? For example if qry_1 returns Joe 14, Jack 16, Jimmy 12 and qry_2 returns Joe 22, Jack 48, Jimmy 66 is there a way to SUM those results in the UNION Query? I tried changing the syntax to a group by like so, but didn't work:
Select Name, Count FROM [C:\DB\DB1.mdb].qry_1
UNION ALL
SELECT Name, Count FROM [C:\DB\DB2.mdb].qry_2
GROUP BY Name, Count
回答1:
For your case nothing changed, use:
SELECT * FROM [C:\DB\DB1.mdb].qry_1
UNION ALL
SELECT * FROM [C:\DB\DB2.mdb].qry_2
UPD: To SUM them i would recommend GROUP BY. Let's say we saved upper query as qry_U then try smth like this:
SELECT [Name], SUM([Numbers]) FROM [qry_U] GROUP BY [Name]
来源:https://stackoverflow.com/questions/23154339/union-query-across-databases