title: How to select row with max value when duplicate rows exist in SQL Server
body: <p>I have table like this </p>
  
  <pre><code>DocumentID        | MasterStepID | StepNumber | RoleID | UserID     | Status
  JIEP/TT/07/000174 | Approval1    |          1 |   NULL | 0006100022 |      1    
  JIEP/TT/07/000174 | Approval1    |          2 |     12 | 0006199013 |      3    
  JIEP/TT/07/000174 | Approval1    |          3 |     13 | 0006106426 |      3
  JIEP/TT/07/000174 | Approval1    |          5 |     18 | 0006100022 |      3
  JIEP/TT/07/000174 | Approval1    |          6 |     16 | 0006104115 |      6
  </code></pre>
  
  <p>I expect result like this</p>
  
  <pre><code>JIEP/TT/07/000174 | Approval1 | 1 | NULL | 0006100022 | 1
  JIEP/TT/07/000174 | Approval1 | 5 |   18 | 0006100022 | 3
  JIEP/TT/07/000174 | Approval1 | 6 |   16 | 0006104115 | 6
  </code></pre>
  
  <p>I try this query but it's return not like what I expect</p>
  
  <pre><code>select  *
  from    WF_Approval sr1
  where not exists
          (
          select  *
          from    WF_Approval sr2 
          where   sr1.DocumentID = sr2.DocumentID and 
                  (
                      sr1.StepNumber &lt; sr2.StepNumber
                  )
          )and MasterStepID = 'Approval1'
  </code></pre>