title: How to use QUERY in Sheets to find most recent grade for each student?
body: <p>I have a spreadsheet containing a list of assessments for students.  It is comprised of four columns:</p>
  
  <pre><code>   A           B         C         D
  Student     Standard    Date     Score
  </code></pre>
  
  <p>On another sheet I have a table containing a list of students in column A and a list of standards in Row 1.</p>
  
  <p>I want to query the spreadsheet of assessments to return the score of the most recent assessment for the current student on the current standard.  Currently I have this formula in cell K3:</p>
  
  <pre><code>=Query(Assessments!A:D,"select D where(A="&amp;$A3&amp;" and B="&amp;K$1&amp;") order by max(C) limit 1")
  </code></pre>
  
  <p>but it gives me this error:</p>
  
  <blockquote>
    <p>Unable to parse query string for Function QUERY parameter  2: AGG_IN_ORDER_NOT_IN_SELECTMAX(<code>C</code>)</p>
  </blockquote>
  
  <p><strong>Edit:</strong>
  I've gotten some great answers, but I guess I asked poorly. What I really need is the score from the most recent assessment. The results from JPV and pnuts have both given the date of the most recent assessment. Here is a stripped down version of the actual file: <a href="https://docs.google.com/spreadsheets/d/15YFtIACyuTcnBkXDbBJiX5KsfYYQyI1QFfDc7-_e4os/edit?usp=sharing" rel="nofollow">spreadsheet</a>.</p>
  
  <p>In the <code>Students</code> sheet I'm needing a formula in the Green cells that results in a number from <code>0</code> to <code>4</code> based on the data in the <code>Assessments</code> sheet.</p>
  
  <p>This is why in the query I was trying to select D, but order by max(C).</p>
  
  <p>I tweaked one of these formulas and got:  </p>
  
  <pre><code>=iferror(query(A3:D20, "Select D where A = '"&amp;G20&amp;"' and B = '"&amp;I20&amp;"' order by C desc limit 1",0), "no data found")
  </code></pre>