使用现有表上的内部联接创建表

时间:2019-04-09 00:05:44

标签: sql sql-server

我可以联接两个表,但是我试图将它们另存为新表,但一直说我的选择语法错误?

我对SQL Server非常陌生

Create table New_table AS
SELECT * 
from Old_Table inner join id on Old_table.id=Other_table.id

1 个答案:

答案 0 :(得分:1)

您需要SELECT ... INTO

SELECT Old_table.id
     , Old_table.foo
     , Other_Table.bar
     , Other_Table.foo AS baz -- foo has to be renamed, can't have two columns with the same name
  INTO New_table 
  FROM Old_Table 
 INNER 
  JOIN Other_Table 
    ON Old_table.id = Other_table.id