Your solution would display all documents that had the highest version
number in the table. Not the Highest version number of each document.
Doc : Vers
A : 1
A : 2
B : 1
B : 2
B : 3
C : 1
C : 2
C : 3
Your solution would return
B : 3
C : 3
What I thought the user wanted would be
A : 2
B : 3
C: 3
You could modify your solution to get the above result.
SELECT [Document Number], [Document Version]
FROM YourTableName
WHERE [Document Version] in (
SELECT TOP 1 [Document Version]
FROM YourTableName as Temp
WHERE Temp.[Document Number] = YourTableName.[Document Number]
ORDER BY [Document Version] DESC)
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.
here is an alternative that I have sometimes used.
SELECT TOP 1 [pay table].[pay rate]
FROM [pay table]
ORDER BY [pay table].[pay rate] DESC;
Using the document version it would be something like:
SELECT TOP 1 [Document Number], [Document Version]
FROM YourTableName
ORDER BY [Document Version] DESC;
As long as document version is numeric, there is no problem. You may
have to watch out if it is alphabetic.
- Show quoted text -