Reputation: 2483
I have a recordset that looks like this:
DocID (Primary Key) | Version | Name
4 | 1 | FileNameA
8 | 2 | FileNameA
6 | 1 | FileNameB
3 | 1 | FileNameC
What I need to do is only show a unique file name where the version number is greater than 1.
So I need a SQL query that would return a recordset that looks like this:
DocID (Primary Key) | Version | Name
8 | 2 | FileNameA
6 | 1 | FileNameB
3 | 1 | FileNameC
All I am using now is a basic select statement from my table. I am not sure if this is possible. Any help would be greatly appreciated.
Upvotes: 2
Views: 541
Reputation: 65157
Get your desired rows from a subselect and join on that:
SELECT DocID, Version, Name
FROM MyTable t
INNER JOIN (SELECT Name, MAX(Version) as Version
FROM MyTable
GROUP BY Name) sub
ON Sub.name = t.name
AND sub.version = t.version
Upvotes: 1