一尘不染

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

sql

在SQL Server中,这会将来自Customers表的100条记录插入到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子句。


阅读 154

收藏
2021-05-05

共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
2021-05-05