title: Referencing outer query's tables in a subquery
body: <p>Is it possible to reference an outer query in a subquery with MySQL? I know there are <em>some</em> cases where this is possible:</p>
  
  <pre><code>SELECT *
  FROM table t1
  WHERE t1.date = (
      SELECT MAX(date)
      FROM table t2
      WHERE t2.id = t1.id
  );
  </code></pre>
  
  <p>But I'm wondering if something like this could work:</p>
  
  <pre><code>SELECT u.username, c._postCount
  FROM User u
  INNER JOIN (
      SELECT p.user, COUNT(*) AS _postCount
      FROM Posting p
      --# This is the reference I would need:
      WHERE p.user = u.id
      GROUP BY p.user
  ) c ON c.user = u.id
  WHERE u.joinDate &lt; '2009-10-10';
  </code></pre>
  
  <p>I know I could achieve the same using a <code>GROUP BY</code> or by pulling the outer <code>WHERE</code> clause into the sub-query, but I need this for automatic SQL generation and cannot use either alternative for various other reasons.</p>
  
  <p><strong>UPDATE</strong>: Sorry, the question led to some confusion: The first query is just a working example, to demonstrate what I <em>don't</em> need.</p>
  
  <p><strong>UPDATE 2</strong>: I need both u.id = p.user comparisons: The first counts users that joined before '2009-10-10', while the other one is a join condition that associates table rows correctly.</p>