When i am trying to retrieve the last value from my data base it returns the first one. By using the following Query.
SELECT [Id] from dbo.Tb_Patient;
I want to get the last value. What query i should use?
When i am trying to retrieve the last value from my data base it returns the first one. By using the following Query.
SELECT [Id] from dbo.Tb_Patient;
I want to get the last value. What query i should use?
Try this
SELECT Top(1) [Id] from dbo.Tb_Patient order by Id desc;
Alternatively if Id
is Auto Incremented column then you can use MAX
function as well to find Maximum value.
SELECT MAX([Id]) from dbo.Tb_Patient