title: select id with the latest date and foreign key
body: <p>I have a table as shown here below.</p>
  
  <p><a href="https://i.stack.imgur.com/8EzBW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8EzBW.png" alt="enter image description here"></a></p>
  
  <p>I want to select the <code>id_start_odon</code> with a particular <code>id_pasien</code> and the last date of that particular <code>id_pasien</code>. I want to get 15 as the result. I've tried this but it doesn't render what I want.</p>
  
  <pre><code>public function get_latest($id_pasien){
      $query = "SELECT s1.id_start_odon FROM start_odon s1 WHERE s1.id_pasien=$id_pasien AND s1.created_at=(SELECT s2* FROM start_odon s2 WHERE s2.id_pasien=$id_pasien AND s2.created_at=MAX(s2.created_at))";
      $res = $this-&gt;db-&gt;query($query);
      return $query;
  
  }
  </code></pre>
  
  <p>Any suggestions are appreciated.</p>