title: Subquery in doctrine2 notIN Function
body: <p>I'd like to select members who are not in specific service. I have 3 tables :</p>
  
  <ul>
  <li><code>membre</code></li>
  <li><code>service</code></li>
  <li><code>membre_service</code> (relation between <code>membre</code> and <code>service</code>)</li>
  </ul>
  
  <p>I'm using doctrine 2 and in SQL my query is :</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT m.* FROM membre m WHERE m.`id` NOT IN (
      SELECT ms.membre_id FROM membre_service ms WHERE ms.service_id != 29
  )
  </code></pre>
  
  <p>In Doctrine, I do :</p>
  
  <pre class="lang-php prettyprint-override"><code>$qb  = $this-&gt;_em-&gt;createQueryBuilder();
  $qb2 = $qb;
  $qb2-&gt;select('m.id')
          -&gt;from('Custom\Entity\MembreService', 'ms')
          -&gt;leftJoin('ms.membre', 'm')
          -&gt;where('ms.id != ?1')
          -&gt;setParameter(1, $service);
  
      $qb  = $this-&gt;_em-&gt;createQueryBuilder();
      $qb-&gt;select('m')
          -&gt;from('Custom\Entity\Membre', 'm')
          -&gt;where($qb-&gt;expr()-&gt;notIn('m.id', $qb2-&gt;getDQL())
      );
      $query  = $qb-&gt;getQuery();
      //$query-&gt;useResultCache(true, 1200, __FUNCTION__);
  
      return $query-&gt;getResult();
  </code></pre>
  
  <p>I got the following error :</p>
  
  <blockquote>
    <p>Semantical Error] line 0, col 123 near 'm WHERE ms.id': Error: 'm' is already defined. </p>
  </blockquote>