Subject | Selecting the Last n rows ... |
---|---|
Author | Anand |
Post date | 2004-01-19T09:44:11Z |
Hi all,
I have a webpage where I am displaying records from my database.
I want to
give the following navigation options to the user:
First | Previous | Next | Last
Each of these options is hyperlinked, and provides a different
input to the
webpage input handler. Based on this input value, I have to
fetch the
necessary number of records from the database. For e.g. if you
click on the
First link, I shall fetch the first 10 records using a query
like this:
SELECT FIRST 10 SKIP 0 FROM <tablename>
Similarly I have programmed the Next and the Previous links as
well.
However I am stuck on the Last link. How do I select the last n
records
from the database? Note that I don't have a recordcount of the
records with
me. I shall have to run a Count(*) query to get a record count.
And since
the database will be in use by many users, there is every chance
that every
time you refresh a page, one of the records has been deleted or
another one
has been added. So I can't rely on an older COUNT(*) value.
Is there any option such as SELECT LAST n SKIP 0 FROM
<tablename> ? This
particular line doesn't seem to work. It fails with the message
Token
unknown, flagging the number at the 'n'. The error code
returned is -104.
I am using IBExpert as the front-end to the Firebird 1.5
database.
Anand Kashelkar
India
__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
I have a webpage where I am displaying records from my database.
I want to
give the following navigation options to the user:
First | Previous | Next | Last
Each of these options is hyperlinked, and provides a different
input to the
webpage input handler. Based on this input value, I have to
fetch the
necessary number of records from the database. For e.g. if you
click on the
First link, I shall fetch the first 10 records using a query
like this:
SELECT FIRST 10 SKIP 0 FROM <tablename>
Similarly I have programmed the Next and the Previous links as
well.
However I am stuck on the Last link. How do I select the last n
records
from the database? Note that I don't have a recordcount of the
records with
me. I shall have to run a Count(*) query to get a record count.
And since
the database will be in use by many users, there is every chance
that every
time you refresh a page, one of the records has been deleted or
another one
has been added. So I can't rely on an older COUNT(*) value.
Is there any option such as SELECT LAST n SKIP 0 FROM
<tablename> ? This
particular line doesn't seem to work. It fails with the message
Token
unknown, flagging the number at the 'n'. The error code
returned is -104.
I am using IBExpert as the front-end to the Firebird 1.5
database.
Anand Kashelkar
India
__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus