title: Retrieve Id of latest record for each user
body: <p>I am asking as the examples I can find don't quite match what my need is.</p>
  <p>I have a table:</p>
  <pre><code>Id        PersonId PersonNumber        StartDate
  --------- -------- ------------------- -----------------
  1         1        E1                  2020-10-21
  2         1        Q1                  2019-01-01
  3         2        E2                  2020-10-01
  4         2        Q2                  2019-10-01
  </code></pre>
  <p>I need to retrieve the Id of the most recent record.  In this case it would be Ids 1 and 3.</p>
  <p>I have been using</p>
  <pre><code>SELECT MAX(Id) AS Id
  FROM PersonNumber AS PersonNumber_1
  GROUP BY PersonId
  </code></pre>
  <p>But that is incorrect because the data may not necessarily have been input in sequential order, so the <code>MAX(Id)</code> may actually be an older record. I tried doing <code>SELECT ID, MAX(StartDate)</code> but that does not work as <code>Id</code> is not used in an aggregation or GROUP BY</p>
  <p>How would I get the <code>Id</code> of the most recent record for each <code>PersonId</code>?</p>