Subject Re: whats the opposite of first?
Author martinknappe
--- In firebird-support@yahoogroups.com, "Adam" <s3057043@...> wrote:
>
> --- In firebird-support@yahoogroups.com, "martinknappe" <martin@>
> wrote:
> >
> > 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)
> >
>
> Martin,
>
> 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
>

Thanx Adam, that helps