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: 

Inconsistent behaviour in group by and order by

sebasv
New Contributor II

Consider this minimal example:

with t as (select explode(sequence(1,10,1)) as id)
select (id%2) as id from t
group by id
order by id

I would expect an ambiguous column name exception, since the grouping and sorting could apply to 2 different `id` columns. Instead the grouping is applied to t.id and the order is applied to (t.id%2).

Is there a setting we can apply to trigger an error when there is ambiguity? Can this be escalated?

2 REPLIES 2

gchandra
Databricks Employee
Databricks Employee

SathyaSDE
New Contributor III

Hi,

This is not an issue, pls understand order of execution of SQL queries. "Order by" clause will always refer to columns selected / displayed (as you are referring as id everywhere I guess there is a confusion).

SathyaSDE_0-1729949420766.pngSathyaSDE_1-1729949460154.png

Ambiguous column name exception occurs when you refer same column names from two tables without aliasing it differently.

I hope it helps!!

 

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group