title: Select a Sum the last 5 rows
body: <p>I'm building a little quiz game in PHP/MySQL. After asking questions I want a screen to display how many of the last round were answered correctly.</p>
  
  <p>Im storing whether they were answered correctly or not in a table that looks like this:</p>
  
  <pre><code>rowID | questionid | playerid | answercorrect |
  1     | 1          | 1        | 1             |
  2     | 2          | 1        | 1             |
  3     | 3          | 1        | 1             |
  4     | 4          | 1        | 1             |
  5     | 5          | 1        | 0             |
  6     | 6          | 1        | 1             |
  7     | 7          | 1        | 1             |
  </code></pre>
  
  <p>I want to see how many of the last x (usually 5) questions were answered correctly.</p>
  
  <p>I thought this would be simple. I'm trying this:</p>
  
  <pre><code>SELECT sum( answercorrect ) FROM `answersgiven` ORDER BY id DESC LIMIT 5 
  </code></pre>
  
  <p>I thought this would sum the <code>answercorrect</code> column for the last 5 rows, giving me an answer of 4, but it's giving me 7, which is the result for ALL of the rows.</p>
  
  <p>I feel like I'm missing something obvious. It seems like a simple thing to want to do.</p>
  
  <p>Any ideas?</p>