title: Select top ties in SQL Server doesn't return expected data
body: <p>I have a table called <code>NdtReports</code> with this data:</p>
  
  <p><a href="https://i.stack.imgur.com/6HIeA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6HIeA.png" alt="enter image description here"></a></p>
  
  <p>Another table called <code>ndtreportdetails</code> with this data:</p>
  
  <p><a href="https://i.stack.imgur.com/ayAhA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ayAhA.png" alt="enter image description here"></a></p>
  
  <p>These two tables are joined based on <code>ndtreportdetails.reportid</code> and <code>Report.id</code></p>
  
  <p>I execute this query :</p>
  
  <pre><code>SELECT TOP 1 WITH TIES 
      NRD.NdtType, NRD.RequestNumber, NR.NdtReportNumber,
      NRD.ResponseReportDatetime, NRD.Defect,
      NRD.ResponseReportNumber, NRD.Remark
  FROM   
      dbo.NdtReportDetails NRD
  LEFT OUTER JOIN 
      NdtReports NR ON NRD.ReportId = NR.Id
  WHERE  
      NRD.JointId = 1661632
      AND NRD.NdtType IN ('RT', 'PT', 'PWHT', 'MT', 'UT')
  ORDER BY 
      NRD.Id DESC
  </code></pre>
  
  <p>It returns this result:</p>
  
  <p><a href="https://i.stack.imgur.com/FH9sy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FH9sy.png" alt="enter image description here"></a></p>
  
  <p>It returns the last recorded of the jointid with maximum id, but I need the last record with maximum id for all types <code>RT,PT,UT</code>. The expected result should be 3 records with id 139189 (PT), 139193 (UT), 139192 (RT)</p>
  
  <p>Text data :
  report:</p>
  
  <pre><code>Id  NdtReportNumber NdtReportDate   UserId  SubmitDateTime  Type
  6292    IR-AFP-AG-PT-0001   2017-01-07 09:15:13.937 59  2017-01-07 09:15:13.917 PT
  6293    IR-AFP-AG-RT-0001   2017-01-07 09:20:54.397 59  2017-01-07 09:20:54.367 UT
  6294    IR-AFP-AG-RT-0001   2017-01-07 09:23:15.513 59  2017-01-07 09:23:15.487 RT
  6295    IR-AFP-AG-RT-000    2017-01-07 09:41:21.807 59  2017-01-07 09:41:21.787 RT
  6296    IR-AFP-AG-RT-000    2017-01-07 09:42:45.427 59  2017-01-07 09:42:45.400 UT
  </code></pre>
  
  <p>NDTreportdetail</p>
  
  <pre><code>Id  ReportId    State   Defect  SubmitDateTime  NdtType ResponseReportNumber    ResponseReportDatetime  Remark  JointId RequestNumber   RequestDatetime
  139189  6292            2017-01-07 09:15:37.207 PT  pt psa res  2017-01-07 09:15:13.957     1661632 pt psa  NULL
  139190  6293            2017-01-07 09:21:14.853 UT  ut result psa   2017-01-07 09:20:54.440     1661632 ut psa  NULL
  139191  6294            2017-01-07 09:23:29.473 RT  dsad    2017-01-07 09:23:15.530     1661632 adasa   NULL
  139192  6295    NULL        2017-01-07 09:41:21.820 RT  NULL    2017-01-07 09:41:21.820 NULL    1661632 NULL    NULL
  139193  6296    NULL        2017-01-07 09:42:45.437 UT  NULL    2017-01-07 09:42:45.437 NULL    1661632 NULL    NULL
  </code></pre>