Showing posts with label hola. Show all posts
Showing posts with label hola. Show all posts

Monday, March 12, 2012

Limiting Results

Hola,
When I want to get the Top most 5 results in SQL Server I use the Top
keyword. How can I get the Bottom most 5 results? Is there any ANSI SQL-92
Convention to do limit the results instead of top?Hello Guy,
Top and bottom are really the same thing, it's just up to the ordering you
use. So all you have to do is "order by [col] desc".
Aaron Weiker
http://aaronweiker.com/

> Hola,
> When I want to get the Top most 5 results in SQL Server I use the Top
> keyword. How can I get the Bottom most 5 results? Is there any ANSI
> SQL-92
> Convention to do limit the results instead of top?|||> When I want to get the Top most 5 results in SQL Server I use the Top
> keyword.
You use this with ORDER BY, right? Otherwise your TOP means nothing and the
results can be quite ambiguous.

> How can I get the Bottom most 5 results?
Change
SELECT TOP 5 * FROM table ORDER BY column
to
SELECT TOP 5 * FROM table ORDER BY column DESC
http://www.aspfaq.com/
(Reverse address to reply.)|||>> Is there any ANSI SQL-92 Convention to do limit the results instead
of top? <<
In Standard SQL, you would use a cursor to sort the table into a
sequential structure. The front end will then handle display.
You can also write a query in such a way as to count the rows with a
self-join -- Google the word "rank".
SQL Server is still a contigous file model under the covers, so it can
expose its implementation with ORDER BY, TOP and other file system
things like that.