Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Top processing returns rows in different order if sorted on a field that has duplicate values

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-05-12 : 06:54:02
Richard writes "Hi,

We use top processing for paging through record sets. This works great until you come across a table which has duplicates field values that the user sorts on. Example a table with 100 rows there is a name field and an email field. The name field is fixed to richard and the email field is unique.

If you execute this: select top 80 ,name,email from Table order by name

The result will be that name richard with email bmb@oo.ie is returned as row 30.

If you now change the sql to be : select top 60 ,name,email from Table and execute

now unfortunatly the position richard with email bmb@oo.ie may be 30.

This messes up the paging as you scroll forward as you cannot say that all the previous records will appear in the same order as they did last time. So records go missing etc when paging through.
To fix you need to add a second unique sort to the end. Is this the way Top works or am I missing something? Thanks for the help."

dsdeming

479 Posts

Posted - 2003-05-12 : 08:16:19
Can you add a second column to the ORDER BY clause: ORDER BY name, email?


Go to Top of Page
   

- Advertisement -