Re: Getting 'n-1'th record.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bhuvan A <bhuvansql(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Getting 'n-1'th record.
Date: 2001-08-21 14:21:37
Message-ID: 29402.998403697@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Bhuvan A <bhuvansql(at)yahoo(dot)com> writes:
> I need ONLY the 'n-1'th record.

See the 'LIMIT' and 'OFFSET' clauses in SELECT. Note the caveat that
you'd better ORDER the rows to be sure you know which is the n-1'th.
Having done an ORDER BY, you could simplify your life by reversing
the ordering and choosing the second row (OFFSET 1 LIMIT 1).

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2001-08-21 14:39:29 Re: Primary vs Unique Index
Previous Message Jeff Eckermann 2001-08-21 14:17:33 Re: split/explode functions