Merging Data from Two Structurally-identical Tables

  • I have two tables with identical structure – Table1 & Table2. Both tables have rows in them. I basically want to merge the two tables, i.e. I want to insert the all the rows from Table2 into Table1 to make one big Table1.

    Can someone show me a script for this?

    Thanks

  • You can do something like

    INSERT INTO TABLE1

    SELECT MY COLUMNS

    FROM TABLE2

    --WHERE IF NEEDED.

    You should be careful that keys and/or unique fields do not overlap.

    edited to remove ()

  • Thanks a bunch - it worked! I tried that earlier with parenthases around the select and it failed.

  • Thanks a bunch - it worked! I tried that earlier with parenthases around the select and it failed.

    Sorry for the confusion. I put the parenthases to show you were to put your columns, not as part of the syntax. :hehe:. I can see how the ( could have been interpreted as part of the syntax. I will edit my post to avoid further confusion.

    Additionally, you can specify what specific columns you want to move over.

    INSERT INTO TABLE1 (column listing) -- () are needed here

    SELECT MY COLUMNS -- () are not needed here

    FROM TABLE2

    --WHERE IF NEEDED.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply