cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

UNION ALL query for two tables, unmatching column names. Need Help.

Anonymous
Not applicable

Hi All,

I am trying to do a UNION ALL command with two tables where one table has a few column names that do not match the other table so I am using AS for an alias to match the column names. I am still having trouble getting the two tables to UNION properly considering the column order and names are matched. Please see below example:

SELECT name, address, location, city

FROM Database.table1

UNION ALL

SELECT platform AS name, address, spot AS location, NULL AS city

FROM Database.table2;

The reason I am doing this is that table 2 are values that didnt join into table 1, so I am adding them into table 1 through a union.

0 REPLIES 0

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now