title: MYSQL - Join only the lastest row from the second table
body: <p>I have patients table and appointments table. I want to query appointments from today and join patient info on the query.</p>
  <p>This</p>
  <pre><code>SELECT a.PatientID, a.DoctorID, a.DT, 
  p.id, p.Name 
  FROM appointment a 
  JOIN Patient p 
  ON p.id = a.PatientID 
  WHERE DATE(DT) = CURDATE() 
  GROUP BY p.id 
  ORDER BY a.DT DESC
  </code></pre>
  <p>Works, but it shows the first row it finds (usually the older one) not respecting the order by (to show only the latest by patient). What am I missing here?</p>
  <p>UPDATE:
  Sorry, I should write it more properly.</p>
  <p>Patient table:</p>
  <pre><code>id Name
  1  Jonathan
  2  Helena
  </code></pre>
  <p>Appointment table</p>
  <pre><code>PatientID DoctorID DT
  1         1        2021-08-27 09:30
  2         1        2021-08-27 10:00
  1         1        2021-08-27 11:00
  </code></pre>
  <p>If I query as I have it, the return will be</p>
  <pre><code>  1         1        2021-08-27 09:30
    2         1        2021-08-27 10:00
  </code></pre>
  <p>Instead of</p>
  <pre><code>2         1        2021-08-27 10:00
  1         1        2021-08-27 11:00
  </code></pre>