9 comments

[ 5.4 ms ] story [ 104 ms ] thread
Irony: "Error establishing a database connection" when I try to access the website.
And why is this voted to the top, as opposed to, lets say, "3 ways of swapping values b/w variables"? :)
(comment deleted)
It has a tiny bit of info at the top, but this is basically an advertisement.
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/o56ask...

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.
True, I've seen people do crazy things when It came to pagination because they didn't think rownum would work.
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.

http://troels.arvin.dk/db/rdbms/#select-limit-offset

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.