![](/img/trans.png)
[英]T-SQL Union, but exclude results from one table based on another without using a temp table?
[英]T-SQL syntax on creating temp table from union
運行本身可以找到
(select * from #T1
union
select * from #T2)
這不是(添加第一行):
select *
into #T3
from
(select * from #T1
union
select * from #T2)
它引發語法錯誤。
正確的語法是什么?
那是無效的語法,使用派生表中的結果集時需要alias
:
select * into #t3
from (select col1, col2, . . .
from #t1
union all
select col1, col2, . .
from #t2
) t; --- alias missing
您不需要子查詢。 只需添加into
后的第一個select
:
select *
into #T3
from #T1
union
select *
from #T2;
請注意,除非您確實確實要承擔刪除重復項的開銷,否則應使用union all
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.