Subject | Re: whats the opposite of first? |
---|---|
Author | Adam |
Post date | 2006-10-18T00:45:37Z |
--- In firebird-support@yahoogroups.com, "martinknappe" <martin@...>
wrote:
It can be done using two stored procedures but it is quite expensive.
procedure foo:
select first 5 id
from mytable
order by 1 desc
into :id
do
begin
suspend;
end
--
select id
from foo
order by 1 desc
You will want a descending index on id so the first n will be fast,
because it will need to retrieve all records before it can spit them
out backwards.
Adam
wrote:
>Martin,
> hi,
>
> when i want to select the first 5 entries from a table i do something
> 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)
>
It can be done using two stored procedures but it is quite expensive.
procedure foo:
select first 5 id
from mytable
order by 1 desc
into :id
do
begin
suspend;
end
--
select id
from foo
order by 1 desc
You will want a descending index on id so the first n will be fast,
because it will need to retrieve all records before it can spit them
out backwards.
Adam