If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Merge Tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-03, 12:32
LouPelagalli LouPelagalli is offline
Registered User
 
Join Date: Oct 2003
Posts: 3
Merge Tables

Hi,

I'm new to SQL.



Is it possible for SQL to input 2 tables (or more) and assuming that each table contains 10 rows and the data formats are identical, merge into a new table with 20 rows.

Thank You in Advance for Your Help,

Lou
Reply With Quote
  #2 (permalink)  
Old 10-13-03, 13:15
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Merge Tables

insert into table3 ( a, b, c )
select a, b, c from table1
union [all]
select a, b, c from table2;

With UNION ALL, any records common to table1 and table2 will be duplicated; with UNION they will not.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 10-13-03, 13:30
LouPelagalli LouPelagalli is offline
Registered User
 
Join Date: Oct 2003
Posts: 3
That's exactly what I was looking for.

Thanks Tony!
Reply With Quote
  #4 (permalink)  
Old 10-15-03, 14:54
LouPelagalli LouPelagalli is offline
Registered User
 
Join Date: Oct 2003
Posts: 3
That did not quite work, maybe because I'm working in MS Access, but it got me going in the right direction.

For some reason it did not like unioning two tables and creating a third, I kept getting errors when I added the INSERT INTO.

Here's what I ended up doing, and it works perfectly!

Query1 is a Union Query
select table1.* FROM table1
UNION ALL select table2.* FROM table2;

Query2 is a Make Table Query
SELECT Query1.*, * INTO Table3
FROM Query1
ORDER BY a , b, c;

By running Query2, Query1 is run to get the unioned Table1 and TABLE2. The tables are formatted and sorted int Table3.

Thanks Tony, you gave me the clues I needed!

Lou
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On