How to get the last row in the table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vnagendra29
    New Member
    • Jan 2007
    • 1

    How to get the last row in the table

    Hi,
    I need to get a last row from the table. Can anyone assist me.

    Regards
    Nagendra
  • i2eye
    New Member
    • Nov 2006
    • 5

    #2
    It depends on what your table structure is like... say you have a table called table_name, and the identifier is a sequence number called column_id, you can do a subquery... that gets the maximum column_id... then the outer query is to return everything else, see below.


    SELECT * FROM table_name WHERE column_id = (
    SELECT max(column_id)
    FROM table_name );

    You may consider looking up Analytical functions as well for a possible solution.

    Comment

    • nunnasujatha
      New Member
      • Nov 2006
      • 24

      #3
      There is somthing called Rowid using which u can select the last record from ur table irrespective of the table structure.


      ex: this table contains two records as shown
      SQL> select * from sujatha_third;

      ROLLNO JOINDATE
      ---------- ------------------
      2 07-DEC-06
      1 07-DEC-06

      SQL> select * from sujatha_third where rowid=(select max(rowid) from sujatha_third);

      ROLLNO JOINDATE
      ---------- ------------------
      1 07-DEC-06


      i hope this helps u.

      Comment

      Working...