Search code examples
sqlunionvertica

Union tables in Vertica SQL where tables have different order of columns?


I have 2 tables in Vertica SQL and how can I union all these tables to create tables as in result ? As you can see tables 1 and table 2 have different order of columns:

enter image description here


Solution

  • Just list the columns in the order you want them:

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