R
rml
Can anyone show or tell me the basic steps for creating a union query? I'm
trying to combine two queries by the PN field.
Thanks.
trying to combine two queries by the PN field.
Thanks.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
John Spencer said:Then you do want a union query.
You should be able to follow the instructions I gave and just add the other
two tables
So you would end up with something like:
SELECT A, B, C, D
FROM TableA
UNION ALL
SELECT A, C, Y, Z
FROM TableB
UNION ALL
SELECT A, x, y, z
FROM TableC
UNION ALL
SELECT A, B, C, D
FROM TableD
Try it, UNION queries don't destroy any data.
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
John Spencer said:Sorting is done at the end of the union, using the field names in the first query.
SELECT A, B, C, D
FROM TableA
UNION ALL
SELECT A, C, Y, Z
FROM TableB
UNION ALL
SELECT A, x, y, z
FROM TableC
UNION ALL
SELECT A, B, C, D
FROM TableD
ORDER BY C, D
Formatting can get tricky. I would normally apply formatting using a control's
format property on a form or report. If you format in the Union query you
would have to use the format function AND that would change the value type
into a string for the column. So, if you formatted column A as currency using
the format function and attempted to sort by that column, you would get a text
sort (1,10,100,12,2,3,5) instead of a numeric sort (1,2,3,5,10, 12,100).
SELECT Format(TableA.A,"Currency") as A, b, c, d
FROM TableA
Union All ...
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.