Question: Based on the following table

```
Table_A

ID   Rev  Description
-----------------------------------
1    1    Some text.
1    2    Some text. Adding more.
1    3    Some text. Ading more & more.

```

The above will keep adding a new row when user updates the description.

I want to take the row with MAX(Rev) [i.e. the latest description]. 

To get this I do the following:

```
;with AllDescriptions As
(
 select 
        ID
        , Rev
        , Description 
        , ROW_NUMBER() over (partition by ID order by Rev desc) as RowNum
        from Table_A
        Where ID = 1
)
select ID, Rev, Description from AllDescription
where RowNum = 1

```

Recently I saw a different approach to getting the same result

```
select b.* from 
(
 select ID, MAX(Rev) as MaxRev 
 from Table_A 
 where ID = 1
 group by ID
) as a
inner join 
(
 select ID, Rev, Description from Table_A where ID = 1
) as b
on a.ID = b.ID and a.MaxRev = b.Rev

```

From learning perspective, I want to know Which of the above two approaches is better? Or if there is even better way to do the same?

Answer: 
The second approach looks like a SQL Server 2000 approach before `Row_Number()` was introduced. This is the [Greatest-n-per-group problem](https://stackoverflow.com/questions/tagged/greatest-n-per-group).

To evaluate them you should look at the execution plans and the I/O Stats by running `SET STATISTICS IO ON`

Of course for the specific example you have given the following would work equally well

```
 select TOP 1
        ID
        , Rev
        , Description 
        from Table_A
        Where ID = 1
ORDER BY Rev desc

```
I would tend to favour the first approach - from a readability perspective, once you're comfortable with the ROW\_NUMBER() OVER ... syntax then it's somewhat more readable. From a performance perspective, I would be surprised if there was much difference between the two - if there is then I would expect that the second would perform worse - but I stand to be corrected on that!