Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get last ID from table

Status
Not open for further replies.

EscapeUK

Programmer
Jul 7, 2000
438
GB
How do i get the last record entered in a table. The table has an ID field which is incremented each time data is entered
 
If it is an Identity column, then you can query @@Identity to get the value of the most recent insert operation for the current connection. It does not work retroactively (you can't go back a day later and ask for the last Identity value for a give table).

Alternatively, you can use
SELECT MAX(MYCOLUMN) FROM MYTABLE
Technically, it won't give you the last entered value, only the highest. Robert Bradley
Got extra money lying around? Visit:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top