union query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two tables with identical fields. I want to query each table for a
creteria without appending, merging, linking etc. the tables. I am not
looking to match values between the tables, just look up info from each, at
one time.
Is a union query the way to go and is there a wizard that will help me?
 
There isn't a good wizard for creating a union query. Try making your
two queries seperate and then copy and paste the SQL into a new query.

[query 1 SQL]
union
[query 2 SQL]

And then, if you want to get fancy and elimintate any dups between the
two, try:

select field1, field2, field3
from
(
[query 1 SQL]
union
[query 2 SQL]
)
group by field1, field2, field3
 
I have two tables with identical fields. I want to query each table for a
creteria without appending, merging, linking etc. the tables. I am not
looking to match values between the tables, just look up info from each, at
one time.
Is a union query the way to go and is there a wizard that will help me?

Yes, but there's no wizard.

It's easy enough though. Create a Query based on one of the tables,
with whatever criteria you want; test it to be sure it's retrieving
the right values.

Then use View... SQL, or the leftmost tool in the query design toolbar
as a dropdown to select SQL view. You'll see something like

SELECT table1.field1, table1.field2, table1.field3 FROM table1 WHERE
<various criteria>;

Edit this to delete the semicolon and add UNION ALL after it; then
copy and paste the SQL after the UNION ALL, and edit all references to
Table1 to Table2 (or whatever your tablenames actually are).

John W. Vinson[MVP]
 
[query 1 SQL]
union
[query 2 SQL]

And then, if you want to get fancy and elimintate any dups between the
two, try:

Actually UNION already elimininates (complete) duplicates. You need to
use UNION ALL to see all records, including dups.

John W. Vinson[MVP]
 
Back
Top