Home » RDBMS Server » Server Administration » Re: retriving last 10 rows
Re: retriving last 10 rows [message #374634] Fri, 22 June 2001 01:09
Sudhakar Atmakuru
Messages: 58
Registered: May 2001
Member
there are two ways. With either rownum or rowid (ORACLE8 or above).
Here it is.

SELECT * FROM your_table (SELECT * FROM your_table ORDER BY ROWNUM DESC) WHERE ROWNUM<=10 ORDER BY ROWNUM DESC;

if you do not add ORDER BY ROWNUM DESC in outer or main select statement, then it lists last 10 rows reverse but not as they are appeared in the table. It lists the 10th row first and first row last. Check it out as you like.
You can also try with ROWID.
Try it out.
SELECT * FROM your_table (SELECT * FROM your_table ORDER BY ROWID DESC) WHERE ROWNUM<=10 ORDER BY ROWNUM DESC;
Remember, rownum is psuedo and does not refer to physical position, but rowid does.
Hope this helps.

Sudhakar.
Previous Topic: updating fields?
Next Topic: Re: retriving last 10 rows
Goto Forum:
  


Current Time: Sat Jul 06 16:14:59 CDT 2024