Subject | Re: Select first 3 and last 3 records |
---|---|
Author | mailmur |
Post date | 2005-06-09T07:08:04Z |
> I need to select the first 3 and last 3 records from a transactionfile This I would imagine would be a simple query as the example below
however Firebird objects to the "order by" clause when a "union"
operator is present
> select first 3 PrnId, InvNoMaybe a derived inner queries could solve this problem.
> from Ordtrn
> where PrnId='21'
> order by InvNo
> union
> select first 3 PrnId, InvNo
> from Ordtrn
> where PrnId='21'
> order by InvNo desc
Select a.* From
(Select first 3 prnid, invno From Ordtrn ... Order by Invno asc) a
UNION
Select b.* From
(Select first 3 prnid, invno From Ordtrn ... Order by Invno desc) b