Subject Re: [firebird-support] Last N records added to a table?
Author Steve Wiser
What about a primary key off of a generator that increments for each
record. Then you can either look at the current value of the generator
or query out the max value of the primary key from the table. Once you
know that you can query out all records where primary key value > max
primary key value - N.

-steve

On Thu, 2005-06-09 at 14:32 -0700, Sam Hunt wrote:

> 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..
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> 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
>
>
>
>
>
>
>


[Non-text portions of this message have been removed]