Solved

SQL to select greatest of group?

Posted on 2008-06-10
3
161 Views
Last Modified: 2010-03-20
Hi, I have a table where the primary keys are DocumentID and RevisionNumber.  Is there a way to formulate a query in SQL such that it selects all the latest revisions; i.e., the highest revision number of each document group?

Thanks.
0
Comment
Question by:riceman0
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
Comment Utility
SELECT [Document Group], Max([Rev Number]) As MaxRev
FROM YourTableName
GROUP By [Document Group]

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
what about this:
select t.*
  from yourtable t
 where t.revisionnumber = DMAX("RevisionNumber", "yourtable", "DocumentID= " & t.DocumentId)

Open in new window

0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Using your field names:

SELECT [Document Group], Max([RevisionNumber]) As MaxRevNumber
FROM YourTableName
GROUP By [Document Group]
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now