?
Solved

Easy/Quick Way to get max value of a field in query of a table

Posted on 2010-04-06
1
Medium Priority
?
313 Views
Last Modified: 2013-11-27
Is there a quick way to get the maximum value from a field/column in a table.  For example, I have a table with several records for each AccountID.  I'm trying to capture the most recent date for every account.  I'm then comparing that to each individual record to see if it is equal.  If it is, then I include the account name. If not, I leave it blank.  This way, the query reads easier.  ie. the account name is not repeated for each record.  I've done this by creating a separate query that groups by ID and has a field for the max date value, which I then compare against this table.  I was just wondering if I could avoid the extra step.
0
Comment
Question by:BBlu
1 Comment
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 600 total points
ID: 29956202
If you mean that you want to see the "max date record" for each account...


SELECT t1.*
FROM SomeTable1 t1 INNER JOIN
    (SELECT t2.AccountID, Max(t2.TheDate) AS MaxDate
    FROM SomeTable t2
    GROUP BY t2.AccountID) AS z ON t1.AccountID = z.AccountID And t1.TheDate = z.TheDate
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This article will show a step by step guide on how to mask column values in Oracle 12c using DBMS_REDACT full redaction option. This option is available on licensed Oracle Enterprise edition as part of Oracle's Advanced Security.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses

599 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