如何合并 SQL 中的两个 table 的列以形成一个包含所有列的最终 table?

how to merge columns of two tables in SQL to form one final table with all columns?

在红移中,我有 table A 200 列和 Table B 300 columns.Both 这些 table 只有 2 个公共列。我想用 A 和 B 的所有列创建最终的 table,其中公共列只出现一次。有简单的方法吗?

尝试对这 2 个匹配列进行简单连接 您可以将这两列用作 Diststyle 和 Sortkey 以提高 redshift 上的性能,因为两个表的 DISTKEY(col1, col2) and SORTKEY(col1, col2)

    Create table final as (
    Select * from A Join B
    On A.col1 =B.col1 and A.col2=B.col2) ;

为避免公共列出现两次,请使用:

CREATE TABLE combined AS
(
SELECT *
FROM A
JOIN B USING (common_col1, common_col2)
)