Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Need expert help... a challenging query
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