Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

SQL to select greatest of group?

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
riceman0
Asked:
riceman0
  • 2
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
SELECT [Document Group], Max([Rev Number]) As MaxRev
FROM YourTableName
GROUP By [Document Group]

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

Open in new window

0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Using your field names:

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now