﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / PersonID with Max(Version) from it... / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 09:44:04 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: PersonID with Max(Version) from it...</title><link>http://www.sqlservercentral.com/Forums/Topic1342746-392-1.aspx</link><description>Looking at the execution plan, group by version looks simplier, 4 operators versus 6.  The table scan and sort have the same cost associated in both.</description><pubDate>Thu, 09 Aug 2012 10:36:30 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: PersonID with Max(Version) from it...</title><link>http://www.sqlservercentral.com/Forums/Topic1342746-392-1.aspx</link><description>Curious, which is the more scalable solution?[code="sql"]DECLARE @persons TABLE(personid INT,version INT);INSERT @personsVALUES(1,1),(1,2),(1,3),(2,1),(2,2),(3,1),(4,1),(4,2);SELECTpersonid,maxversion = MAX(version)FROM @personsGROUP BY personidORDER BY personid;WITH BaseData AS (SELECT    personid,    version,    ROW_NUMBER() OVER (PARTITION BY personid ORDER BY version DESC) rnFROM    @persons)SELECT    personid,    versionFROM    BaseDatawhere    rn = 1;[/code]I guess I'll have to test this at home tonight.</description><pubDate>Thu, 09 Aug 2012 09:58:49 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: PersonID with Max(Version) from it...</title><link>http://www.sqlservercentral.com/Forums/Topic1342746-392-1.aspx</link><description>[quote][b]info 58414 (8/9/2012)[/b][hr]Hi,how can I get effectively max(version) to identify any PersonID with multiple VersionID?[/quote]That's what GROUP BY and MAX are for :)[code]DECLARE @persons TABLE(personid INT,version INT)INSERT @personsVALUES(1,1),(1,2),(1,3),(2,1),(2,2),(3,1),(4,1),(4,2)SELECTpersonid,maxversion = MAX(version)FROM @personsGROUP BY personidORDER BY personid[/code]</description><pubDate>Thu, 09 Aug 2012 09:16:50 GMT</pubDate><dc:creator>mtassin</dc:creator></item><item><title>PersonID with Max(Version) from it...</title><link>http://www.sqlservercentral.com/Forums/Topic1342746-392-1.aspx</link><description>Hi,how can I get effectively max(version) to identify any PersonID with multiple VersionID?[u]PersonID version[/u]1 11 21 32 12 23 14 14 2and so on ...Result1 32 23 14 2Thank youNicole:)</description><pubDate>Thu, 09 Aug 2012 09:10:16 GMT</pubDate><dc:creator>info 58414</dc:creator></item></channel></rss>