title: MySQL to use Group By to pull other varchar field from same row
body: <p>I have a transactions table structured like this:</p>
  
  <pre><code>+--------------------------------------+--------------------------+------------+
  | contact_id                           | return_reason            | date       |
  +--------------------------------------+--------------------------+------------+
  | 2091c2ed-8f9b-bcfe-1884-50d3ab2cd02d | R01 - Insufficient Funds | 2014-01-25 |
  | 2091c2ed-8f9b-bcfe-1884-50d3ab2cd02d | R08 - Payment Stopped    | 2013-09-15 |
  | 2091c2ed-8f9b-bcfe-1884-50d3ab2cd02d | R01 - Insufficient Funds | 2013-08-15 |
  | 2091c2ed-8f9b-bcfe-1884-50d3ab2cd02d | R01 - Insufficient Funds | 2013-07-31 |
  | 2091c2ed-8f9b-bcfe-1884-50d3ab2cd02d | R01 - Insufficient Funds | 2013-05-31 |
  | 10101a4f-eaf8-b05a-4813-51a682df2189 | R08 - Payment Stopped    | 2013-03-15 |
  | 10101a4f-eaf8-b05a-4813-51a682df2189 | R08 - Payment Stopped    | 2013-04-15 |
  | 10101a4f-eaf8-b05a-4813-51a682df2189 | R08 - Payment Stopped    | 2013-05-15 |
  +--------------------------------------+--------------------------+------------+
  </code></pre>
  
  <p>The data I want to find is the most recent return_reason per contact_id. </p>
  
  <p>My current query is this:</p>
  
  <p><code>select contact_id,return_reason as most_recent_return_reason,max(date) as ram_date from transactions group by contact_id order by ram_date desc;</code></p>
  
  <p>The result of my query is pulling the right return_reason but I'm not sure if it's doing it because it's accurate/correct of if it's because the odds are in my favor. I'm afraid because this very similar query pulls the wrong date value:</p>
  
  <p><code>select contact_id,return_reason as most_recent_return_reason,date as ram_date from transactions group by contact_id order by ram_date desc;</code></p>