Hi Wayne,
One other thing that may be
different for your situation....
this brackets/period "virtual table"
will not allow any other brackets
within the construction...
i.e., you cannot use this if your table names
contain spaces -- meaning you would have to
surround the table name(s) with brackets....
this will cause this "SQL construction" to fail.
In addition to Van's optimable suggestion,
if saving the union query is not possible,
I would not have a problem (in Access)
saving the union table (with indexes on fields that
will keep out duplicates from both tables),
then, in DAO code,
Dim db As DAO.Database
Set db = CurrentDb()
db.Execute "DELETE * FROM tblUnion", dbFailOnError
db.Execute "INSERT INTO tblUnion (f1,f2) SELECT f1, f2 FROM tblA",dbFailOnError
db.Execute "INSERT INTO tblUnion (f1,f2) SELECT f3, f4 FROM tblB",dbFailOnError
db.Close
Set db = Nothing
In Access at least, it is preferrable to run update
queries as opposed to make table queries.
Good luck,
Gary Walter
Gary Walter said:
Possibly your situation is not "changing"
the query to the following "form"
SELECT q.F1, q.F2
INTO tblUnion
FROM
[SELECT F1, F2 FROM tblA
UNION
SELECT F3, F4 FROM tblB]. AS q;
I'm sorry I did not mention this...
Access will take earlier "forms"
and automatically put brackets
and ending period around the
"virtual union table."
Apologies,
Gary Walter
WayneM said:
Gary Walter said:
Hi Wayne,
PMFBI
This works in Access.
SELECT q.F1, q.F2
INTO [tblUnion]
FROM
(
SELECT F1, F2 FROM tblA
UNION
SELECT F3, F4 FROM tblB
) As q;
or this works
SELECT F1, F2
INTO [tblUnion]
FROM
(
SELECT F1, F2 FROM tblA
UNION
SELECT F3, F4 FROM tblB
) As q;
or this works (as Van suggested)
SELECT F1, F2
INTO [tblUnion]
FROM
(
SELECT F1, F2 FROM tblA
UNION
SELECT F3, F4 FROM tblB
) ;
Do you see how these are different from what
you "already tried?"
select TblA.F1, TblA.F2 into UnionTbl from TblA Union Select TblB.F3,
TblB.F4 from TblB
Good luck,
Gary Walter
:
:
Not sure whether this work or not but you can try:
SELECT F1, F2
INTO [tblUnion]
FROM
(
SELECT F1, F2 FROM tblA
UNION
SELECT F4, F4 FROM tblB
)
--
HTH
Van T. Dinh
MVP (Access)
I tried your suggestion, but that does not work. It was the first thing I
tried, since this what you would expect to work in sql. Any other
suggestions? How about some type of 'insert into' ?
Thanks for any other ideas. I suppose I could just create a table and then
just do inserts from the union recordset. Ugh. This will be slow.
Thanks,
Wayne
OK, "UNCLE". I give up. I created two tables called tblA and tblB with
fields F1, F2 and F3, F4 (text) and added 2 rows of data. Then I cut and
pasted your syntax into the SQL view of the query builder and got the same
message I always got, which is "Syntax Error on From Clause" with the cursor
highlighting the second Select keyword.
The Union part of the query works fine, but the combination is where the
problem is.
I do believe you, but I must be missing something here. I cannot believe
this is so difficult. Am I this stupid?
Thanks,
Wayne