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 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!