Aim:
Select all distinct values from three different columns, each located in a different table: [QueryA].Att1, [QueryB].Att2, [QueryC].[Att C].
Return all selected values in a single column in a 4th table: [Table1].Field1
The ‘INSERT INTO’ line isn’t working. The rest of it works (makes query) when 1st line is removed.
The rest of it works (makes query) when 1st line is removed.
x
INSERT INTO [Table1].Field1
SELECT DISTINCT [QueryA].Att1
FROM [QueryA]
UNION
SELECT DISTINCT [QueryB].Att2
FROM [QueryB]
UNION
SELECT DISTINCT [QueryC].[Att C]
FROM [QueryC];
Error message:
Syntax error in FROM clause.
Advertisement
Answer
In MS Access, you need to place UNION
in a subquery or entirely separate query to be included in an append. Additionally, period qualifier between table and column should not be used in INSERT INTO
:
INSERT INTO [Table1] (Field1)
SELECT Att1
FROM
(SELECT [QueryA].Att1
FROM [QueryA]
UNION
SELECT [QueryB].Att2
FROM [QueryB]
UNION
SELECT [QueryC].[Att C]
FROM [QueryC]
) AS sub
Alternatively, with a separate query:
INSERT INTO [Table1] (Field1)
SELECT Att1
FROM mySavedUnionQuery