Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

In SQL Server this inserts 100 records, from the Customers table into tmpFerdeen:-

SELECT top(100)*

INTO tmpFerdeen

FROM Customers

Is it possible to do a SELECT INTO across a UNION ALL SELECT:-

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

Not too sure where to add the INTO clause.

1 Answer

0 votes
by (40.7k points)

In SQL Server, you can use this code:

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

Related questions

Browse Categories

...