title: Geting the last entry on join
body: <p>So, I have these 2 tables. One contains, lets call them, bugs, and another contains solutions. One bug may have more than one solution (or state, if you may), and I'd like to get the last one.</p>
  
  <p>Right now, I'm doing it like this:</p>
  
  <pre><code>Select b.*, ap.approveMistakeId 
  from bugs_table as b
  LEFT JOIN (select approveId, approveCause, approveDate, approveInfo, 
                    approveUsername, mistakeId as approveMistakeId 
             from approve_table 
             order by approveDate desc) AS ap 
  ON m.mistakeId = ap.approveMistakeId 
  GROUP BY b.bugId
  </code></pre>
  
  <p>This is not a complete query, it is just to show the how I'm approaching it. The real query joins more than 10 tables.</p>
  
  <p>The problem with this is, that with this subselect, the query runs for about 3.3s and returns ~2.4K records. Without this query, it runs for 0.4s, which is more acceptable. I have created and index on approveDate, but that didn't seem to solve the problem.</p>
  
  <p>Could the solution be a view, that was created from this query, and then joined to this query? Or is there a way to do this in some other manner?</p>
  
  <p>Thanks!</p>