Combine two SQL tables as one?

  • I have two or more related tables that need to be combined as one e.g. i have Survey1, Survey2, Survey3 and i need to just combine all columns/data into one Survey table. How would i do that?

     

    Thanks

     

  • Create a table (newtable) containing all the necessary columns

    insert newtable(columnthatapplies1,2,3,4,n)

    select column1,column2,3,4,n

    from Servey1

    insert newtable(columnthatapplies1,2,3,4,n)

    select column1,column2,3,4,n

    from Servey2

    insert newtable(columnthatapplies1,2,3,4,n)

    select column1,column2,3,4,n

    from Servey3

  • OR

    select column1,column2,3,4,n

    from Survey1

    UNION ALL

    select column1,column2,3,4,n

    from Survey2

    UNION ALL

    select column1,column2,3,4,n

    from Survey3

     


    * Noel

  • i am trying to avoid this approach since each table has about 500 columns ,, there gotta be some more automated way of doing this?

  • if you open QA and DRAG & DROP the Colums Folder into the Editor the Field List gets created for you. It doesn't get better than that

     

     


    * Noel

  • I think that following script would help you..

    SELECT *

    INTO <NEW TABLE NAME>

    FROM <TABLE 1>

    INSERT INTO <NEW TABLE NAME>

    SELECT *

    FROM <TABLE 2>

    INSERT INTO <NEW TABLE NAME>

    SELECT *

    FROM <TABLE 3>

  • I am afraid that is not going to work lakshman. The tables referred to have some of the same columns in them and some different.

Viewing 7 posts - 1 through 6 (of 6 total)

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