C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Selecting last record


Posted Date: 05 Nov 2009      Posted By: Ernest      Member Level: Silver     Points: 1   Responses: 4



Hi,

How to get the last inserted or latest entry/record in a table which take multiple records.

(e.g. customer having multiple orders in Order table and I want the last Order for a specif customer.)





Responses

Author: Neetu    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Try this statement.

select top 1 * from TABLE_NAME order by ID desc

regards
Neetu



Author: Nikhil Gaur    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

use this query

SELECT TOP 1 * FROM tablename

Join this campus group
http://www.dotnetspider.com/sites/637/-ecb-aspdotnet.aspx

Thanks & Regards
NIks
My Software and Web Development Experience



Author: Anuraj    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Select the rows based on the inserted time, you may need to add a DATEFIELD in the db and set the DEFAULT as GETDATE().

ORDER BY Date DESC

Thanks
Anuraj
THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS.
BEWARE OF BUGS IN THE ABOVE CODE; I HAVE ONLY PROVED IT CORRECT, NOT TRIED IT.
dotnetthoghts



Author: atulpatel    05 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

There are couple of ways to do that thing.

1. You can use ID for Order By purpose. and using Top 1,you will get desired output.

2. You can use Time field for Order By the purpose. and using Top 1,you will get desired output.

Thanks,
Atul



Post Reply
You must Sign In to post a response.
Next : How to cross check the new login created in sql server 2000
Previous : SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM ... . Ent
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use