Results 1 to 4 of 4

Thread: Merge Tables

  1. #1
    Join Date
    Oct 2003

    Unanswered: Merge Tables


    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,


  2. #2
    Join Date
    Sep 2002
    Provided Answers: 1

    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.

  3. #3
    Join Date
    Oct 2003
    That's exactly what I was looking for.

    Thanks Tony!

  4. #4
    Join Date
    Oct 2003
    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!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts