Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f7LFFbP38167 for ; Tue, 21 Aug 2001 11:15:37 -0400 (EDT) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.1) with HTTP id 105843 for ; Tue, 21 Aug 2001 08:15:31 -0700 From: "Josh Berkus" Subject: Re: Getting 'n-1'th record. To: pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.4.1 Date: Tue, 21 Aug 2001 08:15:31 -0700 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_===105843====davinci.ethosmedia.com===_" X-Archive-Number: 200108/269 X-Sequence-Number: 4516 This is a multi-part MIME message --_===105843====davinci.ethosmedia.com===_ Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit 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@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco --_===105843====davinci.ethosmedia.com===_ Content-Type: text/plain Content-Disposition: attachment; filename="" Content-Transfer-Encoding: base64 DQo= --_===105843====davinci.ethosmedia.com===_ Content-Type: text/plain Content-Disposition: attachment; filename="" Content-Transfer-Encoding: base64 DQo= --_===105843====davinci.ethosmedia.com===_ Content-Type: text/plain Content-Disposition: attachment; filename="" Content-Transfer-Encoding: base64 DQo= --_===105843====davinci.ethosmedia.com===_--