cisco0407


I need to grab the last three records from sql table . How would i do this

Cisco




Re: SQL SELECT

Kent Waldrop Jn07


Cisco:

If you have a sequence key (such as an IDENTITY column) to the table maybe something like:

Code Snippet

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:

Code Snippet

select top 3 *

from yourTable

order by createDateTime desc

How do you "know" what are the last three records






Re: SQL SELECT

richbrownesq

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