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

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
asked Jul 11, 2019 in SQL by Tech4ever (20.3k points)

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...