I'm sure this is a relatively easy answer, but I'm going blank about how to accomplish this.I'm looking to query a table that includes an ID and version number for each record and returns only the records with the highest version numbers.Take the following as an example:CREATE TABLE #Sample (ID int, Ver int, MyText varchar(10)) INSERT #Sample VALUES (1, 1, 'Zebra 1-1')INSERT #Sample VALUES (1, 2, 'Apple 1-2')INSERT #Sample VALUES (1, 3, 'Zebra 1-3')INSERT #Sample VALUES (2, 1, 'Apple 2-1')INSERT #Sample VALUES (3, 1, 'Zebra 3-1')INSERT #Sample VALUES (3, 2, 'Apple 3-2')INSERT #Sample VALUES (4, 1, 'Zebra 4-1')-- SELECT STATEMENT HERE DROP TABLE #Sample
I want to end up with the following:ID Ver MyText ----------- ----------- ---------- 1 3 Zebra 1-3 2 1 Apple 2-1 3 2 Apple 3-2 4 1 Zebra 4-1