title: Symfony2: Doctrine subquery in the WHERE clause including a LIMIT
body: <p>I'm trying to convert this SQL into either DQL or whatever the query builder variant would look like.</p>
  
  <pre><code>select *
    from project_release r
   where (select s.title as status_name
            from release_status_log l
            left join release_status s
              on l.release_status_id = s.id
           where l.release_id = r.id
           order by l.created_at desc
           limit 1
         ) not in ('Complete', 'Closed')
  ;
  </code></pre>
  
  <p>From inside the repository class for the <code>Release</code> entity, I've tried this</p>
  
  <pre><code>return $this-&gt;getEntityManager()-&gt;createQuery("
      select r.*
        from MyBundle:Release r
       where (select s.title
                from MyBundle:ReleaseStatusLog l
                join l.status s
               where l.release = r
               order by l.createdAt desc
               limit 1
             ) IN ('Complete','Closed')
       order by r.release_date ASC
       limit 10
  ")-&gt;getArrayResult();
  </code></pre>
  
  <p>Which gives the error</p>
  
  <blockquote>
    <p>[Syntax Error] line 0, col 265: Error: Expected
    Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got 'limit'</p>
  </blockquote>
  
  <p>Which is referring to the <code>limit 1</code> in the subquery.</p>
  
  <p>So then I tried this</p>
  
  <pre><code>return $this
    -&gt;createQueryBuilder('r')
    -&gt;select('r.*')
    -&gt;where("(select s.title
                from MyBundle:ReleaseStatusLog l
                join l.status s
               where l.release = r
               order by l.created_at desc
               limit 1
             ) $inClause ('Complete', 'Closed')
    ")
    -&gt;setMaxResults( $limit )
    -&gt;orderBy('release_date', 'ASC')
    -&gt;getQuery()
    -&gt;getArrayResult()
  ;
  </code></pre>
  
  <p>Which gives the same error.  How can I execute a subquery limited to 1 row per row in the parent query?</p>
  
  <ul>
  <li>Symfony 2.0.15</li>
  <li>Doctrine 2.1.7</li>
  <li>PHP 5.3.3</li>
  <li>MySQL 5.1.52</li>
  </ul>