September 24, 2009 at 7:56 am
hi
i have tabe a:
id name version
--------------
1 a 1
2 a 2
3 a 3
4 b 1
5 b 2
6 b 3
7 c 1
8 c 2
9 c 3
i need to query to display version no maxmum records
id name version
--------------
3 a 3
6 b 3
9 c 3
Thanks
Dastagiri.D
September 24, 2009 at 8:12 am
select max(id) id , name, max(version) version
from versions
group by name
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
September 24, 2009 at 8:15 am
this query will work with the data supplied and also incases where the max version and max id are not on the same row
SELECT TableA.id, TableA.name, TableA.version from TableA
INNER JOIN (SELECT name, MAX(version ) AS version FROM TableA GROUP BY name) x
ON tableA.name = x.name and tableA.version = x.version
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply