Subject | Re: [firebird-support] whats the opposite of first? |
---|---|
Author | Milan Babuskov |
Post date | 2006-10-18T19:57:17Z |
martinknappe wrote:
select field
from table t1
where 5 > ( select count(*) from table t2 where t2.field < t1.field )
order by field descending;
If there is index on the "field", this should work fast.
--
Milan Babuskov
http://swoes.blogspot.com/
http://www.flamerobin.org
> when i want to select the first 5 entries from a table i do somethingProvided that you don't have two fields with same value:
> like:
>
> select first 5 field from table order by field ascending
>
> now, what do i do if i want to select the LAST 5 ? (but keeping the
> same order)
>
> select last 5 field from table order by field ascending
>
> doesnt work (fb 1.5)
select field
from table t1
where 5 > ( select count(*) from table t2 where t2.field < t1.field )
order by field descending;
If there is index on the "field", this should work fast.
--
Milan Babuskov
http://swoes.blogspot.com/
http://www.flamerobin.org