Home » RDBMS Server » Server Administration » Re: retriving last 10 rows
Re: retriving last 10 rows [message #374646] Fri, 22 June 2001 09:39
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 (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 (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: Joining Multiple Tables
Next Topic: joining multiple tables
Goto Forum:
  


Current Time: Sat Jul 06 16:03:11 CDT 2024