how to select last row?
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: how to select last row?

  1. #1
    Join Date
    Jul 2000
    Posts
    70
    What sql statement will allow me to select the row that was added LAST to a table?
    thanks.

  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Hopefully you have a timestamp column on your table. Otherwise, you can't do it consistently.
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  3. #3
    Join Date
    Jul 2000
    Posts
    296
    Or a column based on a sequence.

  4. #4
    Join Date
    Dec 2000
    Posts
    9
    Hi

    Use Rowid..

    Ex:
    select * from emp where rowid in (select max(rowid) from emp);

    I hope it works..

  5. #5
    Join Date
    Jul 2000
    Posts
    296
    This does't work. You don't know where new rows are inserted. After rows are deleted, new rows can be inserted in the datablocks of the deleted rows.

  6. #6
    Join Date
    Jul 2000
    Posts
    70
    ok, say I have a timestamp column in the table.
    What sql statment will allow me to select the last row with the latest time stamp.
    An SQL example would help,
    thanks.

  7. #7
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    I agree with akkerend. The rowid will yield the last row in the table, not necessarily the last row inserted into the database.

    If you have a timestamp column:

    select * from emp
    where timestamp_col = (select max(timestamp_col) from emp)
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width