dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: SQL Server
Expertise: Beginner
Jul 15, 1999

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Finding the Latest Date in SQL

Question:
I have a table with a datefield as part of the key. This was needed because it stores historical information. I need to know how to write an SQL query that will supress all records except those with the "latest" date.

The other part of the key is a field named "Trailer Number". I only need to see the trailers with the latest dates (because there are multiple entries for each trailer).

Answer:
You need to apply the MAX function to the date while using the table twice. You can accomplish this by having a self-referencing query using the table twice (MyTable A, MyTable B) or by making a subquery in the WHERE Clause.


(WHERE DATE > (SELECT MAX(DATE) FROM MyTable)
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date