From: | "Josh Berkus" <josh(at)agliodbs(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Getting 'n-1'th record. |
Date: | 2001-08-21 15:15:31 |
Message-ID: | web-105843@davinci.ethosmedia.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Bhuvan,
> An sql query results with 'n' records. OK.
> I need ONLY the 'n-1'th record.
You're making this much harder than it needs to be.
If you want the "nth" record, then you have to be supplying the database
with an ORDER BY. For the next-to-last record, simply reverse the ORDER
BY and take the second record.
e.g.:
If you want the next-to-last (n-1) record from:
SELECT * FROM syslog
ORDER BY entrytime;
Then ask for:
SELECT * FROM syslog
ORDER BY entrytime DESC
LIMIT 1 OFFSET 1;
Easy, no?
-Josh Berkus
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/plain | 2 bytes |
unknown_filename | text/plain | 2 bytes |
unknown_filename | text/plain | 2 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Joseph Shraibman | 2001-08-21 15:24:32 | Re: exists |
Previous Message | Jeff Eckermann | 2001-08-21 15:08:00 | Re: Getting 'n-1'th record. |