Main Page ┬╗ MS Access Snippets ┬╗ Union Query and Make Table Query in Single Code


Union Query and Make Table Query in Single Code


You can combine Union Query and Make Table Query in single MS Access SQL statement.
Here is the code:

sample.txt
SELECT * INTO UNITED_TABLE
FROM (SELECT
[TABLE1].[FIELD1],
[TABLE1].[FIELD2],
[TABLE1].[FIELD3]
FROM
[TABLE1]
UNION ALL 
SELECT
[TABLE2].[FIELD1],
[TABLE2].[FIELD2],
[TABLE2].[FIELD3]
FROM
[TABLE2]) AS TEMPQUERY;

TABLE1 and TABLE2 are the tables which we combine by using Union Query under the name of TEMPQUERY.
TEMPQUERY doesn't shown anywhere, it is created temporarily.
SELECT * INTO UNITED_TABLE statement makes table from result of TEMPQUERY and rename it as UNITED_TABLE.
Download example file


´╗┐