Re: Getting 'n-1'th record.

From: "Jeff Eckermann" <jeckermann(at)verio(dot)net>
To: "Bhuvan A" <bhuvansql(at)yahoo(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Getting 'n-1'th record.
Date: 2001-08-21 15:08:00
Message-ID: 023901c12a53$11c61190$279c10ac@INTERNAL
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)yahoo(dot)com>
To: <pgsql-sql(at)postgresql(dot)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
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2001-08-21 15:15:31 Re: Getting 'n-1'th record.
Previous Message Josh Berkus 2001-08-21 14:39:29 Re: Primary vs Unique Index