Click to See Complete Forum and Search --> : fixed number of result records


max
05-07-2003, 11:14 AM
How can one indicate the maximum number of result records that should be returned in an SQL string?
E.g. when a DB table containing 5000000 records is read out with an SQL query, the WHERE clause can filter the number of records, but can return up to 5M records. Is it possible to indicate in the SQL query the maximum number of records that should be returned to optimize performance?

DaPi
05-07-2003, 11:16 AM
Look at e.g. "AND ROWNUM <= 10" as part of the condition - beware if you have a sort you won't win on execution time.

jmodic
05-07-2003, 04:28 PM
Originally posted by DaPi
... beware if you have a sort you won't win on execution time.
In fact you'll probably win on execution time enormously, however the returned result will probably not be the one expected....:p

DaPi
05-08-2003, 03:11 AM
Is it really neccessary to say "if you want the right result" in every posting? :)

So, the answer to every tuning question is:
SELECT 1 FROM DUAL;
It's very fast, there's no disk activity and it's the shortest select statement I can think of.
On the other hand it might not be the result you want!