Search code examples
sqlsql-serverinsert-into

SELECT INTO using union of two old tables


I am trying to issue a SELECT * INTO <new_table_name> FROM <old_table_name> statement where my select statement is the result of combining two other tables.

In pseudocode format, it would look like:

SELECT *
FROM <table1>
UNION ALL
SELECT *
FROM <table2>

INTO 
<new_table>

None of my current attempts have been valid. Can anyone offer a suggestion?


Solution

  • INTO will go immediate after SELECT statement (SELECT . . . INTO) :

    SELECT *
    INTO <new_table>
    FROM <table1> 
    UNION ALL
    SELECT *
    FROM <table2>