小编典典

是否可以将 SELECT INTO 子句与 UNION [ALL] 一起使用?

all

在 SQL Server 中,这会将 100 条记录从 Customers 表插入到 tmpFerdeen 中:-

SELECT top(100)*
INTO tmpFerdeen
FROM Customers

是否可以跨 UNION ALL SELECT 执行 SELECT INTO :-

SELECT top(100)* 
FROM Customers
UNION All
SELECT top(100)* 
FROM CustomerEurope
UNION All
SELECT top(100)* 
FROM CustomerAsia
UNION All
SELECT top(100)* 
FROM CustomerAmericas

不太确定在哪里添加 INTO 子句。


阅读 108

收藏
2022-08-02

共1个答案

小编典典

这适用于 SQL Server:

SELECT * INTO tmpFerdeen FROM (
  SELECT top 100 * 
  FROM Customers
  UNION All
  SELECT top 100 * 
  FROM CustomerEurope
  UNION All
  SELECT top 100 * 
  FROM CustomerAsia
  UNION All
  SELECT top 100 * 
  FROM CustomerAmericas
) as tmp
2022-08-02