Sample Header Ad - 728x90

Strange behavior of TOP 1 clause sql server

0 votes
2 answers
846 views
I have a SQL Server database and restored it on another server on a different machine. Now I run following same query on both DBs which produces same below result set.
select person_id, visit_id, verification_code, mobileNo, created_date
from person
order by verification_code, created_date DESC
enter image description here But when I add TOP 1 clause to the above query, original DB shows the 2nd row (ignores first row)
select TOP 1 person_id, visit_id, verification_code, mobileNo, created_date
from person
order by verification_code, created_date DESC
enter image description here while restored DB shows first row enter image description here I thought it might be due to different collation, but I checked both servers have same collation.
Asked by user1543848 (75 rep)
Apr 20, 2021, 09:03 AM
Last activity: Apr 20, 2021, 11:38 AM