PC Review


Reply
Thread Tools Rate Thread

2 queries into one table?

 
 
=?Utf-8?B?VGF5bG9y?=
Guest
Posts: n/a
 
      16th Feb 2006
Hey,
Okay first of all, I am very new to Acces, SQL, etc. and I did check the
UNION help but I couldnt figure it out.
I have 2 queries that have the data I need but I need that data combined
into 1 table or query so I can export the combined data into a .csv file.
Here is what I have been playing with:

Select[CombinedDataTable] Query1 UNION [ALL] [TABLE] Query2 [UNION [ALL]
[TABLE] queryn [ ... ]];

I believe that the [ALL] and [TABLE] things need to say something else. I am
not sure I need the "CombinedDataTable". If I do need to create that table,
would it have the fields of the queries?

My only workaround is runing my queries individually and saving them to two
seperate .csv files then using copy and paste to combine the date. That takes
too long. Any help?

Thanks
 
Reply With Quote
 
 
 
 
tina
Guest
Posts: n/a
 
      16th Feb 2006
well, the "UNION Operation" topic in Access Help is confusing (at least in
A2003). from your post, sounds like you're working with two queries, that
you want to combine into one dataset. here's a copy of the example in the
"Examples of union querys (MDB)" topic, which does just that:

SELECT [CompanyName], [City]
FROM [Suppliers]

UNION SELECT [CompanyName], [City]
FROM [Customers]
ORDER BY [City];

this is basically a union of two Select queries. you might find it easier to
substitute your own table and field names by looking at the following:

SELECT [FieldName], [AnotherFieldName]
FROM [QueryName]

UNION SELECT [FieldName], [AnotherFieldName]
FROM [AnotherQueryName]
ORDER BY [SomeFieldName];

you don't need to include the ORDER BY clause unless you want to sort the
records in the dataset. also, you can include the ALL keyword if you don't
mind having any duplicate records included in the dataset. (as the Help
says, the query will run faster that way, because the system doesn't have to
compare records in a search for duplicates to exclude.) the syntax would be

SELECT [FieldName], [AnotherFieldName]
FROM [QueryName]

UNION ALL SELECT [FieldName], [AnotherFieldName]
FROM [AnotherQueryName]
ORDER BY [SomeFieldName];

the important thing to see in the example is that each SELECT statement
includes the same *number* of fields - in this case, 2 fields. that equal
balance is required in a Union query.

if the above doesn't quite get you there, post back with the SQL statements
from your two queries, and we'll see if we can help you figure it out.

hth


"Taylor" <(E-Mail Removed)> wrote in message
news:457F3266-78E6-4B42-96B2-(E-Mail Removed)...
> Hey,
> Okay first of all, I am very new to Acces, SQL, etc. and I did check the
> UNION help but I couldnt figure it out.
> I have 2 queries that have the data I need but I need that data combined
> into 1 table or query so I can export the combined data into a .csv file.
> Here is what I have been playing with:
>
> Select[CombinedDataTable] Query1 UNION [ALL] [TABLE] Query2 [UNION [ALL]
> [TABLE] queryn [ ... ]];
>
> I believe that the [ALL] and [TABLE] things need to say something else. I

am
> not sure I need the "CombinedDataTable". If I do need to create that

table,
> would it have the fields of the queries?
>
> My only workaround is runing my queries individually and saving them to

two
> seperate .csv files then using copy and paste to combine the date. That

takes
> too long. Any help?
>
> Thanks



 
Reply With Quote
 
=?Utf-8?B?Qml6IEVuaGFuY2Vy?=
Guest
Posts: n/a
 
      16th Feb 2006
Hi Taylor,

Try something like this:

SELECT * FROM Table1
UNION
SELECT * FROM Table2;

To get a successful union your tables need to line up with each other. i.e.
same number of fields and similar data types in sequence.

If the tables are not the same, make two separate queries, ensuring that the
number of fields match and the sequence of fields is as you want in the final
product. If you have an smaller number of fields in one query, balance it out
by using Null As [Missingfeildname]. Do this for each missing field.
View the queries as SQL, Copy the SQL from one and paste into the other.
Before the 2nd SELECT statement type "UNION" and delete the ";" at the end of
the first SELECT statement.

Hope it helps

Nick

"Taylor" wrote:

> Hey,
> Okay first of all, I am very new to Acces, SQL, etc. and I did check the
> UNION help but I couldnt figure it out.
> I have 2 queries that have the data I need but I need that data combined
> into 1 table or query so I can export the combined data into a .csv file.
> Here is what I have been playing with:
>
> Select[CombinedDataTable] Query1 UNION [ALL] [TABLE] Query2 [UNION [ALL]
> [TABLE] queryn [ ... ]];
>
> I believe that the [ALL] and [TABLE] things need to say something else. I am
> not sure I need the "CombinedDataTable". If I do need to create that table,
> would it have the fields of the queries?
>
> My only workaround is runing my queries individually and saving them to two
> seperate .csv files then using copy and paste to combine the date. That takes
> too long. Any help?
>
> Thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Table Security: Retricting Update queries to only run to one table jon.ingram@comcast.net Microsoft Access VBA Modules 1 28th Nov 2007 08:53 AM
Using append/update queries to transfer record data from one Table to another Table DiDi Microsoft Access Queries 1 4th Jan 2007 04:12 PM
Multi-table queries are not visible as datasource for a Word table =?Utf-8?B?a2ZzY2hhZWZlcg==?= Microsoft Access External Data 1 28th Jul 2005 10:41 AM
Refreshing Make Table Queries and Append Queries =?Utf-8?B?SmltbXkgRw==?= Microsoft Access 3 4th Feb 2005 04:25 PM
Re: Make Table Queries table deletion messages John Vinson Microsoft Access Queries 0 19th Aug 2003 07:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:07 PM.