Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Records issue using top keyword in sql query

I have a Linq query which is working fine but i have noticed when i use take keyword with that query it does not return the same top selected records. When i saw the Sql profiler query they are totally same excepts just top keyword in that what may be the problem. One more thing i have noticed is when i give a no greater then records in database it works fine with take as well.

I am attaching the query and records attachment

enter image description here

and when I apply top 10 in this query it shows this records

enter image description here

What could be the problem im using Sql Server 2008 R2.

like image 880
Fraz Sundal Avatar asked Dec 01 '25 08:12

Fraz Sundal


1 Answers

Using TOP keyword without ordering does not guarantee repeatability of resultset.

From here

If a SELECT statement that includes TOP also has an ORDER BY clause, the rows to be returned are selected from the ordered result set. The whole result set is built in the specified order and the top n rows in the ordered result set are returned.

like image 198
Oleg Dok Avatar answered Dec 04 '25 00:12

Oleg Dok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!