我想使用以下查询在SQL Server中创建一个新表。我无法理解为什么此查询无法正常工作。
Query1:作品
SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2
Query2:不起作用。错误:Msg 170, Level 15, State 1, Line 7 Line 7: Incorrect syntax near ')'.
Msg 170, Level 15, State 1, Line 7 Line 7: Incorrect syntax near ')'.
SELECT * INTO [NEW_TABLE] FROM ( SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2 )
谢谢!
您必须为SQL Server中的派生表定义表别名:
SELECT x.* INTO [NEW_TABLE] FROM (SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2) x
在此示例中,“ x”是表别名。