Re: Getting 'n-1'th record. - Mailing list pgsql-sql

From Jeff Eckermann
Subject Re: Getting 'n-1'th record.
Date
Msg-id 023901c12a53$11c61190$279c10ac@INTERNAL
Whole thread Raw
In response to Getting 'n-1'th record.  (Bhuvan A <bhuvansql@yahoo.com>)
List pgsql-sql
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
>
>



pgsql-sql by date:

Previous
From: Joseph Shraibman
Date:
Subject: Re: exists
Next
From: Stephan Szabo
Date:
Subject: Re: exists