Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Retrieve last N rows
You can use MINUS and ROWNUM functions to get the result. Check the Oracle
docs for detailed description.
Example to get the last two records from a table is:
SQL> select * from demo;
ID DATA
---------- ------------------------------ 1 TEST 2 ONE MORE TEST 3 ANOTHER ONE 4 FINAL TEST
SQL> SELECT * FROM demo WHERE ROWNUM < (SELECT COUNT(*)+1 FROM demo)
2 MINUS
3 SELECT * FROM demo WHERE ROWNUM < (SELECT COUNT(*)-1 FROM demo);
ID DATA
---------- ------------------------------ 3 ANOTHER ONE 4 FINAL TEST
Check the latest Oracle DBA forums at:
http://www.dbaclick.com/cgi-bin/ib3/ikonboard.cgi
Hope that helps,
Trifon Anguelov
Senior Oracle DBA