last record

  • Hi All,

    I am using sql server, my questin is i want to get a last record from a table

    sachin

  • Write a SELECT statement that has a WHERE clause with selection criteria that gives you the row that is "last" by your definition.

    There is no inherent last row in a SQL Server table

     

  • Maybe this will help. I recently needed to get the last record ID from my table.

    SELECT TOP 1 recordID

    FROM yourTable

    ORDER BY recordID DESC

    Of course I am using SQL 2K but it should work fine in 2005.

  • Which will work if you have an identity column called recordID

    Inherently, SQL keeps no record of the 'last' row. If there's an identity column or a last inserted time then you can order on those to get the latest record. Otherwise, there's no way to tell.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply