Re: SQL Question

From: Chun-Yen <agi_at_haa.com.tw>
Date: 2000/07/24
Message-ID: <8lg5fc$n7c$1_at_nnrp1.deja.com>#1/1


Hello,

You can also build an Index on the column, then select /*+ INDEX_DESC(tname i_iname)*/ ....... this is the fastest way to retrive the top n records, even the table is large.
By the way,how about the 11th to 20th records ??

Same as above,just add a alias in the subquery:   select *
    from ( select /*+ INDEX_DESC...)*/ rownum seq,....

             from tname
            where ......
              and sal > 0 )

   where seq between 11 and 20
   order by seq

Agi Chen

In article <3973ef29.0_at_gaspra.oss.akzonobel.nl>,   "martijn" <mlinsen_at_vx8000.nl> wrote:
> Works great!! Thanks
>
> Eugenio wrote in message <8kv1li$c0n$1_at_mailint03.im.hou.compaq.com>...
> >If id is a unique/PK column, this could help you.
> >
> >select v.id, v.count
> >from (select rownum num, v1.*
> > from (select id, count
> > from table_name
> > group by count, id) v1) v,
> > (select count(*) maxnum from table_name)
> >where num > maxnum-10
> >
> >--
> >Ciao
> >
> >Eugenio
> >remove _nospam from reply address
> >
> >Opinions are mine and do not necessarily reflect those of my company
> >
> >=======================================================
> >?eljko JuriƦ wrote in message <8kus68$hnv$1_at_as102.tel.hr>...
> >>
> >>> select * from (
> >>> select * from table_name order by count desc )
> >>> where rownum <=10;
> >>>
> >>
> >>Sorry,
> >>
> >> Probably works with v.8.x by in my case doesn't help... (see
 version
> >>bellow) :-(
> >>
> >>
> >>=============================================================
> >>SQL*Plus: Release 3.3.2.0.2 - Production on Mon Jul 17 12:51:36 2000
> >>
> >>Copyright (c) Oracle Corporation 1979, 1994. All rights reserved.
> >>
> >>
> >>Connected to:
> >>Oracle7 Server Release 7.2.2.4.0 - Production Release
> >>PL/SQL Release 2.2.2.3.0 - Production
> >>
> >>
> >>===============================================================
> >>
> >>
> >>
> >>
> >
> >
>
>

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Mon Jul 24 2000 - 00:00:00 CEST

Original text of this message