A GROUP BY
would be enough to get every maximum version for every recID
.
SELECT Ver = MAX(Ver), recID FROM YourTable GROUP BY recID
If you also need the appropriate identifier, you can wrap it in a subquery
SELECT yt.* FROM Yourtable yt INNER JOIN ( SELECT Ver = MAX(Ver), recID FROM YourTable GROUP BY recID ) ytm ON ytm.Ver = yt.Ver AND ytm.recID = yt.RecID
or, depending on the version of SQL Server you are using, use ROW_NUMBER
SELECT * FROM ( SELECT ID, Ver, recID , rn = ROW_NUMBER() OVER (PARTITION BY recID ORDER BY Ver DESC) FROM YourTable ) yt WHERE yt.rn = 1
source share