How do i use a union query? (1 Viewer)

-=fREaKy=-

Registered User.
Local time
Today, 13:20
Joined
Feb 4, 2002
Messages
12
Thanx
 

ZanyJanie

Registered User.
Local time
Today, 13:20
Joined
Mar 27, 2001
Messages
30
In your query, go into SQL View and type in your select statements

The first select statement establish the name and order of fields within your query.

Example:

SELECT LastName, FirstName, SSN FROM Table1
UNION SELECT lname, fname, SS_Num FROM table2

In your query results set, the fields would be named LastName, FirstName, and SSN and they would contain the data from both Table1 and Table2



[This message has been edited by ZanyJanie (edited 03-26-2002).]
 

-=fREaKy=-

Registered User.
Local time
Today, 13:20
Joined
Feb 4, 2002
Messages
12
Hey ZJ, thanx for your help.

I have successfully merged 2 tables, but one of the fields (Product_ID) is not formatted the way it was in the original table.

How can I change this?

Also because it is not like the original, there is now no more primary key (the Product_ID) which I really need obivously


Is there anyway to change this?

Thanx for your help
 

ZanyJanie

Registered User.
Local time
Today, 13:20
Joined
Mar 27, 2001
Messages
30
Your union query fields should take on the same data format as the fields in your first table. One suggestion would be to reverse the order in which you select fields from your two tables; but, that won't solve the PK problem.

Another approach would be to use append queries.

Create a table that has the field structure you want, to including defining your Product ID field as the primary key.

Next, create a delete query that deletes all of the records from this new table.

Next, create two separate append queries ... one each to append the records from your two tables.

Last of all, instead of using the union query, execute the 3 queries (delete, append, append) in succession.

This will take up a bit more disk space, since you're creating a real table, instead of a virtual query table; but you should be able to achieve the results you want.


[This message has been edited by ZanyJanie (edited 04-02-2002).]

[This message has been edited by ZanyJanie (edited 04-02-2002).]
 

Users who are viewing this thread

Top Bottom