The 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.
I'm largely ignorant of commercial RDBMS's, having worked almost entirely with open source ones. So I had assumed that LIMIT was part of some SQL standard. Looking into it further, I realize that I've been wrong about that for a long time.
Yeah, that's one of the things I miss when I have to work with Oracle. Oracle's method of limit result set sizes feels like such a hack and leaks implementation information needlessly. It's not like Oracle couldn't implement something like LIMIT, they just choose not to.
9 comments
[ 5.4 ms ] story [ 104 ms ] threadselect * 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/o56ask...
http://troels.arvin.dk/db/rdbms/#select-limit-offset