小编典典

是否可以将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子句。


阅读 182

收藏
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