【问题标题】:Union tables in Vertica SQL where tables have different order of columns?Vertica SQL 中的联合表,其中表的列顺序不同?
【发布时间】:2021-01-29 13:57:22
【问题描述】:

我在 Vertica SQL 中有 2 个表,如何合并所有这些表以创建结果表?如您所见,表 1 和表 2 的列顺序不同:

enter image description here

【问题讨论】:

    标签: sql union vertica


    【解决方案1】:

    只需按照您想要的顺序列出列:

    select col1, col2, col3
    from table1
    union all
    select col2, col1, null
    from table2;
    

    【讨论】:

      【解决方案2】:

      使用 SELECT INTO 和 UNION ALL 可以解决您的问题

      SELECT * INTO TEMP TABLE RESULT FROM TABLE1
      UNION ALL 
      SELECT * FROM TABLE2 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多