From: Jeff Eckermann <jeckermann@verio.net>
To: Bhuvan A <bhuvansql@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: Getting 'n-1'th record.
Date: Tue, 21 Aug 2001 10:08:00 -0500
Message-ID: <023901c12a53$11c61190$279c10ac@INTERNAL> (raw)
References: <Pine.LNX.4.20.0108211259150.4090-100000@Larry.bks>
SELECT *
FROM table
ORDER BY field DESC
LIMIT 1
OFFSET 1;
This way you don't need to know the value of "n" in advance.
The descending ORDER BY is to indicate a reversal of your intended ordering,
so as to make the n-1'th record the second record.
Note that getting the n-1'th record from an unordered list will not give
meaningful results, because you cannot predict what will be returned.
----- Original Message -----
From: "Bhuvan A" <bhuvansql@yahoo.com>
To: <pgsql-sql@postgresql.org>
Sent: Tuesday, August 21, 2001 2:41 AM
Subject: Getting 'n-1'th record.
>
> hi all,
>
> consider below..
>
> An sql query results with 'n' records. OK.
> I need ONLY the 'n-1'th record.
>
>
> HOW CAN I GET THIS?
>
> Thankx in advance!
>
>
======================================================================
> Q: What's the difference between the 1950's and the 1980's?
> A: In the 80's, a man walks into a drugstore and states loudly, "I'd
> like some condoms," and then, leaning over the counter, whispers,
> "and some cigarettes."
>
>
======================================================================
>
> Regards,
> Bhuvaneswar.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jeckermann@verio.net, bhuvansql@yahoo.com
Subject: Re: Getting 'n-1'th record.
In-Reply-To: <023901c12a53$11c61190$279c10ac@INTERNAL>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox