从 LEFT JOIN 保存输出 table

Save output table from LEFT JOIN

我想左连接两个 table,但我无法保存结果 table。

当我使用下面的代码时,我得到了想要的结果:

SELECT *
FROM tableA a
LEFT JOIN tableB b ON a.ID = b.ID AND a.Name = b.Name

但是,当我想将结果保存在新的 table 中并使用:

SELECT *
INTO new_table
FROM tableA a
LEFT JOIN tableB b ON a.ID = b.ID AND a.Name = b.Name

我收到以下错误

Column names in each table must be unique

基于其他问题,我尝试通过以下方式解决此问题:

SELECT a.ID, a.Name
INTO new_table
FROM tableA a
LEFT JOIN tableB b ON a.ID = b.ID AND a.Name = b.Name

但是,现在生成的 table 仅包含列 ID 和名称。以及 tableB.

中的 none 列

非常感谢任何帮助。

您可以为 A 中的列添加别名(您实际上只-需要- 为需要唯一的列添加别名,但您可以选择为其余列分配别名)或 B 使用 AS 关键字使它们唯一并且然后添加 B

中的所有列
SELECT a.ID AS A_ID,
       a.Name AS A_Name,
       b.*
INTO new_table
FROM tableA a
LEFT JOIN tableB b ON a.ID = b.ID and a.Name = b.Name