title: Doctrine delete by subquery with in same table
body: <p>I am trying to delete record from mysql using doctrine</p>
  
  <p>Corresponding MYSQL Query</p>
  
  <pre><code>DELETE FROM user_fields_data WHERE id NOT IN (
      SELECT * FROM (
          SELECT id FROM user_fields_data WHERE id IN (
              SELECT block_id FROM user_fields_data WHERE template = 1
          )
      ) AS `ss`
  ) AND template = 1
  </code></pre>
  
  <p>Trying to delete using Doctrine:</p>
  
  <pre><code>$qb = $this-&gt;_em-&gt;createQueryBuilder();
  
  $blockId = $qb-&gt;select('bl.blockId')
      -&gt;from('UserFieldBundle:UserFieldsData','bl')
      -&gt;where('bl.template = 1');
  
  $ids = $qb-&gt;select('bl2.id')
      -&gt;from('UserFieldBundle:UserFieldsData','bl2')
      -&gt;where($qb-&gt;expr()-&gt;in('bl2.id',$blockId-&gt;getDQL()));
  
  $result = $qb-&gt;delete('UserFieldBundle:UserFieldsData','USF')
      -&gt;where($qb-&gt;expr()-&gt;notin('USF.id', $ids-&gt;getDQL()))
      -&gt;andWhere('USF.template = :templateId')
      -&gt;setParameter('templateId', 1)
      -&gt;getQuery()
      -&gt;getSQL();
  
  dump($result);
  </code></pre>
  
  <p>Doctrine query ends with error:</p>
  
  <blockquote>
    <p>[Syntax Error] line 0, col 65: Error: Expected Literal, got 'DELETE'" </p>
  </blockquote>
  
  <p>Database Structure:</p>
  
  <p><a href="https://www.db-fiddle.com/f/8V8ctsecVBKSNgsCrhuc4/1" rel="nofollow noreferrer">https://www.db-fiddle.com/f/8V8ctsecVBKSNgsCrhuc4/1</a></p>