Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Need expert help... a challenging query

Re: Need expert help... a challenging query

From: Pierre Charpenay <pcharpenay_at_unilog.fr>
Date: Fri, 17 Dec 1999 14:16:51 +0100
Message-ID: <385A37C3.84A14FB9@unilog.fr>

Damon Hastings a écrit :

> Quick question... how can I make the query "find all records with foo >
> x, sort the results by 'bar', and give me only the top 10" as efficient
> as possible, given that there are millions of records with foo > x?
>

Quick response ! Just take the query "starting with the first 'bar', find then 10
first rows with foo > x".
So, you just need an index on 'bar' and this :

select ... from ...
where bar>y /* where 'y' is aa always lowest value */  and foo > x
 and rownum <= 10
/

That's all !

Pierre Received on Fri Dec 17 1999 - 07:16:51 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US