Union query to combine datas in 2 tables.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, I need help with procedure to create union query to combine datas in 2 tables.
I'm not doing any projects as such just learning it...
I have googled and found that union query can do it.
So please help.

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi, I need help with procedure to create union query to combine datas in 2 tables.
I'm not doing any projects as such just learning it...
I have googled and found that union query can do it.
So please help.

Thanks

pedie:

Your information is a little sparse but essentially you can do this:

Select Field1NameHere, Field2NameHere, Field3NameHere, Field4NameHere
From Table1NameHere
Union
Select Field1NameHere, Field2NameHere, Field3NameHere, Field4NameHere
From Table2NameHere

if you want all records even if they are duplicated you would use UNION ALL

Select Field1NameHere, Field2NameHere, Field3NameHere, Field4NameHere
From Table1NameHere
UNION ALL
Select Field1NameHere, Field2NameHere, Field3NameHere, Field4NameHere
From Table2NameHere


And you can add information like if you wanted to know which table it came from:

Select Field1NameHere, Field2NameHere, Field3NameHere, Field4NameHere, "Table1" As MySource
From Table1NameHere
UNION
Select Field1NameHere, Field2NameHere, Field3NameHere, Field4NameHere, "Table2" As MySource
From Table2NameHere


So I hope that gets you started anyway.
 
Upvote 0
Hi Bob, thank you very much..i think this should work...make sense..but i need to check it out...'m installing office10 at the moment..i try right after it finishes...

'll get back soon.

I think in a query we need to ; ' etc in the end of the query do i need to place this or just "," after field names like you have shown?
 
Upvote 0
Pedie

You should put ; and the end of a query, but sometimes Access will let you away with not doing it.

It has nothing to do with fields, a list of fields is separated by a column not a ;.

Note if you do use ; for a UNION query it goes right at the end - not after each separate 'sub' query.
 
Upvote 0
Thanks Norie for clarification...
I had problem installing office10, so i'm reinstalling 07...:confused:
So 'll be checking this out latter..
 
Upvote 0
Can I also please help me out with this...
I have a table with 2 fields...
Owner and 2nd_Owner

I have two access 07 files...
Can a quiry/code run from one db1 and add rec to table in db2

when the code runs i want db1, form1.textbox1 value to go to db2 table called "tb_ownership" field 2nd_Owner. and owner field be updated with environ ("Username")

Thanks again for valuable support..
 
Upvote 0
The easiest method is to link the table from the second database and then just run an append query in the first to update that linked table.
 
Upvote 0
Access doesn't require the semi-colon. It is really optional.


The easiest method is to link the table from the second database and then just run an append query in the first to update that linked table.


Thanks again Bob, the thing is that the admin will not be able to access db1 from db2..only db1 can update db2 [because db2 is main database..]
So can a user click on something and then add this small data by unlocking the maindatabase and locking it back when the update is done?

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top