Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create table in SQL Server using union

In mysql we write query as

create table new_table as (select a.* from Table1 a union select b.* from Table2 b)

This syntax doesn't work in SQL Server - what's the way around for creating a table from union in SQL Server?

like image 386
Davinder Kumar Avatar asked Jun 28 '26 18:06

Davinder Kumar


1 Answers

in SQL Server, you can use SELECT .. INTO

 select a.* 
 into   new_table
 from   Table1 a 

 union 

 select b.* 
 from   Table2 b
like image 157
Squirrel Avatar answered Jul 01 '26 09:07

Squirrel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!