title: Subquery to obtain last record
body: <p>I have 2 tables: <code>User</code> and <code>Session</code>. For each User, I would like know if the last record in session table was created last year.</p>
  
  <p>I tried the following, but it doesn't work:</p>
  
  <pre><code>SELECT *
  FROM(
      SELECT MAX(`Session`.acDateF) as MaxDateF
      FROM `Session`
      WHERE `Session`.acType='1'
  ) as AcDate
  GROUP BY `Session`.userId) 
  WHERE YEAR(`Session`.acDateF) =YEAR(CURRENT_DATE())-1
  </code></pre>
  
  <p>If the User has a record in the <code>Session</code> table this year it doesn't appear in the result.</p>