I have a table, with these columns:
ID | Data
How to find out which record has highest ID?
I have a table, with these columns:
ID | Data
How to find out which record has highest ID?
To get the largest ID:
select max(ID) from myTable
To get a record that has the largest ID:
select *
from MyTable
where ID = (Select max(ID) from myTable)
select *
from YourTable
where ID = (select max(ID) from YourTable)
As well as max, you can use TOP on SQL Server
select TOP 1 * from myTable order by id desc
For joint top
select TOP 1 WITH TIES * from myTable order by id desc
Other engines have LIMIT not TOP. This can give the whol record without a separate MAX sub-query too