Subject Re: [firebird-support] Last N records added to a table?
Author Sam Hunt
Clay Shannon wrote:

><<I have newly created table with no records, but will grow with time
>and then I will need to obtain the last N records added to it, in the
>order in which they where added.
>
>I appreciate any solutions or ideas. Currently using FB 1.5.2.>>
>
>How about:
>
>SELECT FIRST N FROM MESA
>ORDER BY CREATED DESC
>
>(where "created" is a timestamp column)
>
>?
>
>Clay Shannon,
>Dimension 4 Software
>
>
>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>Visit http://firebird.sourceforge.net and click the Resources item
>on the main (top) menu. Try Knowledgebase and FAQ links !
>
>Also search the knowledgebases at http://www.ibphoenix.com
>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
I guess the question I have is how do you know in advance how many N
records you need?
If this is ordered by a timestamp field, why not just get all recs
beginning on a cetain timestamp?

But, if you really do need the last N recs, how 'bout select count(*),
then move to the record at (count(*) - N + 1) and read and write each
rec one-at-a-time to a temp file, then query the temp file. ugly, but
it will work.

Sam H..