Reputation: 75
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)
Upvotes: 3
Views: 116
Reputation: 3267
This can be used to create another table of same type
CREATE TABLE new_table
AS (SELECT * FROM old_table);
Upvotes: 0
Reputation: 223422
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?
Upvotes: 1