3

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)
4

2 回答 2

1

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?

于 2013-03-11T07:08:02.893 回答
0

This can be used to create another table of same type

CREATE TABLE new_table
  AS (SELECT * FROM old_table);
于 2013-03-11T07:17:38.980 回答