Re: Top 20 records in a table ??

From: Connor McDonald <connor_mcdonald_at_yahoo.com>
Date: Mon, 10 Jan 2000 20:35:39 +0800
Message-ID: <3879D21B.3ADF_at_yahoo.com>


Lindsay Walker wrote:
>
> SELECT pay
> FROM emp
> WHERE rownum < 21
> ORDER BY pay DESC
>
> > How to select the highest 20 records from a table via sql*plus ??
> > For example,
> > emp table
> > ----------------
> > id number(5),
> > name varchar2(20),
> > pay number(8)
> >
> > how to select the highest 20 pay from emp ??

This will not get the 'top' 20, just the 'first' 20.

select * from
  ( select * from emp order by pay desc) where rownum < 21

will do the trick...

HTH

-- 
===========================================
Connor McDonald
"These views mine, no-one elses etc etc"
connor_mcdonald_at_yahoo.com

"Some days you're the pigeon, and some days you're the statue."
Received on Mon Jan 10 2000 - 13:35:39 CET

Original text of this message