I need to grab the last three records from sql table . How would i do this
Cisco
Transact-SQL
Cisco:
If you have a sequence key (such as an IDENTITY column) to the table maybe something like:
select top 3 *
from yourTable
order by theKey desc
If you don't have a sequence key but have an "create date/time" column you can do something like:
select top 3 *
from yourTable
order by createDateTime desc
How do you "know" what are the last three records
Last 3 records according to what Date created You need to have some form of unique identifier to ensure that the records are pulled out in the correct order.
SELECT TOP 3 *
FROM myTable
ORDER BY DateCreated DESC