473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Union Query Question

From reading Access 97 help text, it seems that to do what I need to
do will require a Union Query. As this would be my first, I think I
might require a little guidance.

I have two tables with 10 fields that have like data (for instance
both have an item description field, an item price field, a general
notes field, etc.) but with different field names. The tables have
approximately 20/40 other fields that are dissimilar and not needed
for the query. Access help indicated that in order to do a Union Query
each table must have an identical number of fields. So, is the
creation of two new tables, or two selection queries a requirement in
order to satisfy, or are there other workarounds?

I assume somewhere there is an option to select an existing field name
or create a new one? Would there be any other issues to focus on?

Thanks for your help.
Nov 12 '05 #1
3 10516
Each query in the union must return the same number and order of fields, the
tables do not have to match. You can use a calculated field to fill-in data
for fields the underling table is missing. Also look-up the difference
between UNION and UNION ALL to ensure you get all the records you need. The
easiest way to build the UNION is to create each query separately then cut
and past between the SQL windows.

"Dalan" <ot***@safe-mail.net> wrote in message
news:50**************************@posting.google.c om...
From reading Access 97 help text, it seems that to do what I need to
do will require a Union Query. As this would be my first, I think I
might require a little guidance.

I have two tables with 10 fields that have like data (for instance
both have an item description field, an item price field, a general
notes field, etc.) but with different field names. The tables have
approximately 20/40 other fields that are dissimilar and not needed
for the query. Access help indicated that in order to do a Union Query
each table must have an identical number of fields. So, is the
creation of two new tables, or two selection queries a requirement in
order to satisfy, or are there other workarounds?

I assume somewhere there is an option to select an existing field name
or create a new one? Would there be any other issues to focus on?

Thanks for your help.

Nov 12 '05 #2
you already have the tables (so you don't need new tables)
you can use two queries but you don't have to.
the fieldnames have to be the same.
look at the examples in the help (they use the AS keyword)
also consider the ALL keyword (UNION ALL SELECT)
(or you may get less records than you expect)
"Dalan" <ot***@safe-mail.net> wrote in message
news:50**************************@posting.google.c om...
From reading Access 97 help text, it seems that to do what I need to
do will require a Union Query. As this would be my first, I think I
might require a little guidance.

I have two tables with 10 fields that have like data (for instance
both have an item description field, an item price field, a general
notes field, etc.) but with different field names. The tables have
approximately 20/40 other fields that are dissimilar and not needed
for the query. Access help indicated that in order to do a Union Query
each table must have an identical number of fields. So, is the
creation of two new tables, or two selection queries a requirement in
order to satisfy, or are there other workarounds?

I assume somewhere there is an option to select an existing field name
or create a new one? Would there be any other issues to focus on?

Thanks for your help.

Nov 12 '05 #3
You need to make sure you alias the field names so the aliases/names
match... Say you have two tables that are union-compatible (field
types are the same).

TableA(Field1, Field2, Field3)

TableB(FieldA, FieldB, FieldC)

SELECT TableA.Field1 As FieldA, TableA.Field2 As FieldB, TableA.Field3
As FieldC
FROM TableA
UNION ALL
SELECT FieldA, FieldB, FieldC
FROM TableB...

then you can query that result... but NOTE one thing... You CANNOT
update it. (because there's no way to find the original record's table
from a union query).
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dmb000006 | last post by:
My question is about a UNION query to deal with an (annoying) JOIN over two tables. I am joining over a double column primary key (where the order of the columns can be changed). This is sooo...
3
by: Edward | last post by:
I am having conceptual trouble with the following query: select r.ServiceID,r.ContractID,sum(Total) from ( select csc.ServiceID,c.ContractID, sum(csc.ContainerMovement) as Total from...
5
by: Arvin Portlock | last post by:
I can't come up with a query that works. Can anyone help? Conceptually the relationships are easy to describe. I have a table for books (Entries), a table for authors (Authors), and a linking...
3
by: Chip R. | last post by:
Hi, This isn't really an access question, but as I'm really new to SQL I don't know where I would post this. Any suggestions on that would also be helpful. Now on to the question... I am...
2
by: marco | last post by:
Dear List, as it seems, MS SQL as used in Access does not allow a select INTO within a UNION query. Also, it seems that a UNION query can not be used as a subquery. Maybe my (simplified)...
2
by: Thomas | last post by:
Hi All. I think that if I explain the database layout first it may be easier to ask my question. Table Name Field Name Test TestCode Description SpecimenRequirements FeeSchedule TestCode...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
2
kcdoell
by: kcdoell | last post by:
Hello: I am trying to create a union query but do not have a lot of experience. Basically I have the below tables: The Tables: Table Name = tblPrior CreditRegIDFK; Number; Foreign Key...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.