Click here to Skip to main content
15,912,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

Can any one please give me the query to select the latest record from the table?

i.e., most recent record which has been inserted into the table.


Thanks and Regards,
Posted
Comments
Raj.rcr 29-Nov-11 3:03am    
Thanks all...!

Try this one:

SQL
SELECT TOP 1 * FROM [TABLENAME] ORDER BY id DESC


Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard
 
Share this answer
 
Comments
thatraja 29-Nov-11 2:12am    
5!
[no name] 29-Nov-11 2:14am    
thanks
RaisKazi 29-Nov-11 5:12am    
My 5.
Here other couple of ways

how to read the last row with SQL Server[^]
 
Share this answer
 
Comments
RaisKazi 29-Nov-11 5:12am    
My 5.
To get the latest record at least you have A Unique Valued Column, which will help you to get latest row. here is syntax

SELECT TOP 1 * FROM table_Name ORDER BY unique_column DESC 
 
Share this answer
 
Comments
thatraja 29-Nov-11 2:11am    
Why down-vote for this? 5!
RaisKazi 29-Nov-11 5:12am    
My 5.
If you have a primary key, pick up the last primary key (by using max on it).
 
Share this answer
 
Comments
thatraja 29-Nov-11 2:11am    
Why down-vote for this? 5!
Abhinav S 29-Nov-11 3:33am    
Thanks for your counter vote thatraja.
RaisKazi 29-Nov-11 5:14am    
My 5. Without comments/Feedback/Alternate Solution Down-Vote sounds rude. I too got one Down-Vote today for my valid answer(Surprisingly from the Unknown Member having high points).
http://www.codeproject.com/Answers/291638/app-config-reading-problem#answer1
Abhinav S 29-Nov-11 5:40am    
Thanks for the 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900