February 1, 2007 at 1:10 am
Hi All,
I am using sql server, my questin is i want to get a last record from a table
sachin
February 1, 2007 at 7:40 am
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
February 6, 2007 at 2:34 pm
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.
February 7, 2007 at 12:18 am
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
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply