如何在UNION中使用`SELECT ... INTO`?

时间:2013-08-25 12:26:47

标签: sql select

我在从两个表的联合复制到临时表时遇到问题。

我正在使用的代码是

Select * into #tmp from table1 union table2

2 个答案:

答案 0 :(得分:4)

您错过SELECT

table2
SELECT *
INTO   #tmp
FROM   table1
UNION
SELECT *
FROM   table2 

SQL Fiddle

答案 1 :(得分:1)

请改为尝试:

select *
into #temp
from (select * from table1
      union
      select * from table2
     ) t;