3 ms·
SELECT column FROM table WHERE ROWNUM <= 10 Won't give you the expected results in all cases. You need to do something like select * from ( SELECT column FROM
by adamilardi 16y ago
SELECT column FROM table WHERE ROWNUM <= 10
Won't give you the expected results in all cases. You need to do something like
select * from (
SELECT column FROM table order by x
)
WHERE ROWNUM <= 10
This will ensure all your ordering is done before the limiting bit of the query.
Here are more examples
http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html http://www.oracle.com/technology/oramag/oracle/06-sep/o56ask...
- ww520 16y agoThe title of the article is misleading. It should be "Returning the FIRST 10 rows of a result set" instead of TOP 10 rows. All the sample SQL uses the natural order of the tables, but he implied ordering when he talked about other programmers sorting the result rows in program, so it's really confusing. People often mistaken the natural order of a table the same as the sorted order of a result set.
- adamilardi 16y agoTrue, I've seen people do crazy things when It came to pagination because they didn't think rownum would work.