Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Retrieve last record

Posted on 2007-07-26
2
Medium Priority
?
337 Views
Last Modified: 2012-06-22
I have an SQL database with thousands of records in it. The "formnumber" field is set as the key. I am writing a VB.NET application and one of the fields will require me to pull the last record in the database. I don't want to read in all the records and then sort them. Is there a way to sort the data and then read in the last record?
0
Comment
Question by:swuit
  • 2
2 Comments
 
LVL 33

Accepted Solution

by:
hongjun earned 500 total points
ID: 19575176
Use this sql statement

Select Top 1 * From YourTable Order By YourField DESC
0
 
LVL 33

Expert Comment

by:hongjun
ID: 19575181
Key is to sort in descending order.
Then use Top 1 to get the first record.
So effectively, you are getting the last record.

hongjun
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question