Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL nesting queries

I wish to write two nested queries of create and select statements. My motive is to create a new table which includes columns and entries from two other tables. I wrote a query but it is giving me an error.

create table table_3(select * from table_1,table_2)
like image 802
user Avatar asked Mar 09 '26 12:03

user


1 Answers

For SQL Server you can use:

SELECT * 
INTO table_3
FROM table_1, table_2

If you want to join the two tables based on some key then:

SELECT * 
INTO table_3
FROM table_1 JOIN table_2 on table_1.ID = table_2.FKID

You may see: SQL SERVER – CTAS – Create Table As SELECT – What is CTAS?

like image 105
Habib Avatar answered Mar 12 '26 02:03

Habib



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!