Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Retrieve last N rows

Re: Retrieve last N rows

From: Trifon Anguelov <trifona_at_pacbell.net>
Date: Tue, 23 Apr 2002 15:18:38 GMT
Message-ID: <iXex8.797$OD2.273145954@newssvr13.news.prodigy.com>


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

http://www.dbaclick.com




"Md Irfan" <irfan_pk_at_hotmail.com> wrote in message news:c42168e7.0204230510.4b93ab48_at_posting.google.com...
> Hi,
>
> Could any one help me in getting the last N rows from a table? Oracle
7.3.4
> Thanks.
Received on Tue Apr 23 2002 - 10:18:38 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US