title: MySql GROUP BY Max Date
body: <p>I have a table called <code>votes</code> with 4 columns: <code>id</code>, <code>name</code>, <code>choice</code>, <code>date</code>.
  <br>
  <br>
  ****<code>id</code>****<code>name</code>****<code>vote</code>******<code>date</code>***
  <br>
  ****<code>1</code>*****<code>sam</code>*******<code>A</code>******<code>01-01-17</code>
  <br>
  ****<code>2</code>*****<code>sam</code>*******<code>B</code>******<code>01-05-30</code>
  <br>
  ****<code>3</code>*****<code>jon</code>*******<code>A</code>******<code>01-01-19</code>
  <br><br>
  My ultimate goal is to count up all the votes, but I only want to count 1 vote per person, and specifically each person's most recent vote.</p>
  
  <p>In the example above, the result should be 1 vote for A, and 1 vote for B.</p>
  
  <p>Here is what I currently have:</p>
  
  <pre><code>select name,
      sum(case when uniques.choice = A then 1 else 0 end) votesA,
      sum(case when uniques.choice = B then 1 else 0 end) votesB
  FROM (
      SELECT id, name, choice, max(date)
      FROM votes
      GROUP BY name
  ) uniques;
  </code></pre>
  
  <p>However, this doesn't work because the subquery is indeed selecting the max date, but it's not including the correct <code>choice</code> that is associated with that max date.</p>