Skip to content
Advertisement

How to deal with ambiguous column reference in sql column name reference?

I have some code:

I then try

but I get an error

Error in SQL statement: AnalysisException: Reference ‘A.CDE_WR’ is ambiguous, could be: A.CDE_WR, A.CDE_WR.; line 6 pos 4

in databricks. How can I deal with this?

Advertisement

Answer

This query:

is using SELECT *. The * is shorthand for all columns from both tables.

Obviously the combined columns from the two tables have duplicate column names; at least, CDE_WR and CDE_dist — and there may be others. The general solution is to list all the columns out:

However, this is often shorted to:

Note that I changed the table aliases to be reasonable abbreviations for the table names, making the query much clearer and easier to maintain.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement