I am trying to run ORDER BY on a huge data set and produce dense rank values to extract the distinct number of rows based on the dense rank.Later, I am using the dense rank value as a surrogate key in my entire process to carry forward the intermediate results and use it further for some performance testing.
Issue I am facing :-
The problem I am having is I migrated the data set from Matrix(postgresql)(PRODUCTION environment) to SQL Server(New environment ) and implemented the dense rank function. But because of having different dense rank results which is due to the ORDER BY clause behavior in SQL Server and Matrix I am not able to proceed further in validating the code and results.
Test Example:-
SELECT *,DENSE_RANK() OVER ( ORDER BY Col ) AS drnk FROM
(
SELECT '#2 Mayfair Terrace' AS Col
UNION
SELECT '#2 MYSTIC COURT' AS Col
)Z;
SQL Server output :-
Col drnk
#2 Mayfair Terrace 1
#2 MYSTIC COURT 2
Matrix(Postgresql) output :-
Col drnk
#2 MYSTIC COURT 1
#2 Mayfair Terrace 2
Can someone tell me why there is a difference in the behavior of ORDER BY between two different database environments? Any help would be appreciated. Thanks.