General information
Category:
Coding, syntax & commands
Environment versions
Network:
Windows 2000 Server
>>>>The TOP N clause works following way:
>>>>1. All records that match criterias are pulled out into temp result set.
>>>>2. The temp result set is sorted by ORDER BY
>>>>3. The first N records are moved to the final result set. If there're records after Nth with the same sort key, they also included. It means that result cursor can have more than N records.
>>>>
>>>>In this case all 2500 records are pulled out into the temp record set and each gets random value in the rn field. After sorting on the rn field the first 150 records (with the lowest not highest value in the rn field) are copied into resulting cursor. It's unlikely that there would be more than 150 records in the result because of "(RAND() * 1000000)" but in the application you would want to add some code to insure that.
>>>
>>>Spaseebo. Ochen khoroshaw. :-)
>
>Pogalusta. :)
I seldom get opportunities to practice my highschool Russian. And not having the Cyrillic alphabet available kind of puts a crimp in it anyway.
A, nechevo.
>>But, why the lowest values instead of the highest?
>
>>TOP N means get the first N records in the sort order. To get the higest values use ORDER BY rn DESC
Okay, that helps. "TOP" means "first" in the specified sort order, not necessarily "highest" in any sense.
Thanks.
Ken
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only