locked
How to append two tables and put the result in a table? RRS feed

  • Question

  • Hello Team

    I have these two statements that give some results, I need to append these two results from each statement and save the query in a table so I put as this:

    SELECT *

    INTO Final

    FROM (SELECT * From table1) as dtTable1

    UNION

    FROM (SELECT * From table2) as dtTable2

    This query gives me error, how can I rewrite it? Also, is there anyway to put the result of the query into a table other than I have put on the top?

    Regards,

    GGGGGNNNNN

    Regaqrds,

    GGGGGNNNNN


    GGGGGNNNNN

    Wednesday, October 16, 2013 11:29 PM

Answers

  • Try this.

    SELECT *
    INTO Final
    FROM
    (
    SELECT * From table1
    UNION
    SELECT * From table2
    ) as A
    
    

    Or

    SELECT * into FInal
    From table1
    UNION
    SELECT * From table2


    Vinay Valeti| If you think my suggestion is useful, please rate it as helpful. If it has helped you to resolve the problem, please Mark it as Answer

    • Proposed as answer by Olaf HelperMVP Thursday, October 17, 2013 3:31 AM
    • Marked as answer by cloudsInSky Thursday, October 17, 2013 4:06 PM
    Wednesday, October 16, 2013 11:57 PM

All replies

  • Try this.

    SELECT *
    INTO Final
    FROM
    (
    SELECT * From table1
    UNION
    SELECT * From table2
    ) as A
    
    

    Or

    SELECT * into FInal
    From table1
    UNION
    SELECT * From table2


    Vinay Valeti| If you think my suggestion is useful, please rate it as helpful. If it has helped you to resolve the problem, please Mark it as Answer

    • Proposed as answer by Olaf HelperMVP Thursday, October 17, 2013 3:31 AM
    • Marked as answer by cloudsInSky Thursday, October 17, 2013 4:06 PM
    Wednesday, October 16, 2013 11:57 PM
  • It worked, thank you very much,

    GGGGGNNNNN


    GGGGGNNNNN

    Thursday, October 17, 2013 4:06 PM