Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Problem with rownum
Your queries are both saying the same thing:
1) Fetch all rows from artikel where nummer > 60000 2) Stop fetching after you find the first row. 3) Order the results (which consist of just one row)
In your first query, since you are only selecting an indexed value, it is likely that your query is only using the index (not the table)... Thus, it *just so happens* that the results for # 1 are coming back already in order, and "luckily" this means you got 60001.
Your second query is doing the exact same thing, except since you want all of the columns, the CBO is reading directly from the table... so the results of #1 are coming back in whatever order they were stored on the table (having nothing to do with Nummer). The first row now *just so happens* to be 68048 - not the row you were looking for.
GQ has already posted the query you actually are trying to run.
Another approach is:
SELECT * FROM (
SELECT *
FROM Artikel A
ORDER BY NUMMER)
WHERE ROWNUM < 2
Received on Tue Jan 11 2005 - 12:43:39 CST
![]() |
![]() |