Anup
Anup

Reputation: 13

Why do I get different sort order of the same query executed in Teradata & Snowflake?

I am getting different sort order even if I have added order by clause in both the queries. Here are queries that I am executing on Teradata & snowflake-

Teradata :

Select column1, column2, column3, column4,column5 From Teradata_Table  Where column1 in (1027837724,1040965189,1046224751) and column2='2021-03-11'
order by column1 ; 

Result -->

column1 column2 column3 column4 column5
1027837724 3/11/2021 0 42.66 5942
1027837724 3/11/2021 12052.34 2.99 5735
1040965189 3/11/2021 5336.72 10.87 5944
1040965189 3/11/2021 0 311.16 5942
1046224751 3/11/2021 0 14.99 5735
1046224751 3/11/2021 0 2.99 5735

Snowflake :

Select column1, column2, column3, column4,column5 From Snowflake_Tablename  Where column1 in (1027837724,1040965189,1046224751) and column2='2021-03-11'
order by column 1

Result -->

column1 column2 column3 column4 column5
1027837724 3/11/2021 12052.34 2.99 5735
1027837724 3/11/2021 0 42.66 5942
1040965189 3/11/2021 5336.72 10.87 5944
1040965189 3/11/2021 0 311.16 5942
1046224751 3/11/2021 0 14.99 5735
1046224751 3/11/2021 0 2.99 5735

Upvotes: 1

Views: 1055

Answers (1)

Felipe Hoffa
Felipe Hoffa

Reputation: 59175

As the comments say:

  • You are only sorting by one column, and the order of the rows ordered by that column is the same regardless of database.
  • But you are not asking the database to sort by any other column, so rows that have the same column1 can be presented in any arbitrary order.

If you want to make the order consistent, you should ORDER BY column1, column2, column3, etc.

Upvotes: 2

Related Questions