rowcount + order by w/o the wait ?!?!
Posted on 2002-03-05
Using Sybase 12. Is there a cleaver way to "order by" without retrieving a whole result set?
Please take a look at the simplified example below:
set rowcount @my_count
order by my_value desc
Now, is there a way to get Sybase to just return @my_count number of rows, using the order by, without having to retrieve the whole result set first, then ordering, then returning the @my_count rows?
Obviously, there is no problem if the data set is small, but given a large data set, then having to order it, can be taxing.
A range (where my_value between @low and @high) is not possible as the ranges aren't known at query time.
A non-unique, clustered index (my_value) exists on the table.
A loop or cursor to get the max(my_value) where less then the last max(my_value) @my_count number of times is not an option either. (Although, if someone can prove that it is the most efficient way for any @my_count and table size, then I'm all for it! :)
Any help would be appreciated.