Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Limitting result without ROWNUM
Charles Hooper wrote:
> DA Morgan wrote:
>> Charles Hooper wrote: >>> Method #3: >>> SELECT >>> R.ID, >>> FIRSTNAME, >>> LASTNAME, >>> HEIGHT, >>> AGE >>> FROM >>> (SELECT >>> ID, >>> ROW_NUMBER() OVER (ORDER BY HEIGHT DESC) POSITION >>> FROM >>> T1) R, >>> T1 >>> WHERE >>> R.POSITION<=10 >>> AND R.ID=T1.ID; >>> >>> The results of the above methods look something like this: >>> ID FIRSTNAME LASTNAME HEIGHT AGE >>> --------------------------------------- >>> 2 SUSAN SMITH 65 20 >>> 3 DOROTHY SMITH 62 21 >>> 4 JOHN SMITH 72 35 >>> 5 DAVID SMITH 73 34 >>> 7 ROBERT SMITH 76 45 >>> 10 SUSAN JOHNSON 65.5 20 >>> 11 DOROTHY JOHNSON 62.5 21 >>> 12 JOHN JOHNSON 72.5 35 >>> 13 DAVID JOHNSON 73.5 34 >>> 15 ROBERT JOHNSON 79 45 >>> >>> Charles Hooper >>> PC Support Specialist >>> K&M Machine-Fabricating, Inc. >> Impressive but an impressive contrivance. But ROW_NUMBER, ROWNUM, the >> difference is? ;-) >> >> Why not just build a table with ten rows and then use it the way we >> use dual as a source of a single result? >> -- >> Daniel A. Morgan >> University of Washington >> damorgan_at_x.washington.edu >> (replace x with u to respond) >> Puget Sound Oracle Users Group >> www.psoug.org
Possibly. Though personally I am more inclined to think the instructor needs to be taken to the woodshed. ;-) My take on the exercise is that it was an exercise in contrivance.
Here's the roughly comparable question I gave my students last quarter
for comparison:
Rerun the SQL statement for question 7 and obtain an EXPLAIN PLAN using
DBMS_XPLAN. Now rewrite the query in another form and run an EXPLAIN
PLAN on it also. Submit both EXPLAIN PLANS as well as the SQL and an
explanation as to which SQL statement you would choose and why.
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace x with u to respond) Puget Sound Oracle Users Group www.psoug.orgReceived on Sat Jan 20 2007 - 18:50:25 CST
![]() |
![]() |