title: PHP Symfony DQL - Too few parameters: the query defines 1 parameters but you only bound 0
body: <p>i am trying to put together a SELECT in symfony repository project but for some reason getting error message in the subject. Been working on it for a few days but cannot find a solution with different variations of the code. This is the code</p>
  
  <pre><code>$qb3 = $this-&gt;getEntityManager()-&gt;createQueryBuilder();
  $qb3-&gt; select('check.userid')
      -&gt; from('App\Entity\YY_Table', 'check')
      -&gt; where('DATE_FORMAT(now(), \'%e-%b-%Y\') - DATE_FORMAT(check.datecreated, \'%e-%b-%Y\') &lt;=360');
  
  $qb2 = $this-&gt;getEntityManager()-&gt;createQueryBuilder();
  $qb2-&gt; select('((:numemails1 / COUNT(subs.id)) * 10)')
      -&gt; from('App\Entity\XX_Table', 'subs')
      -&gt; where($qb2-&gt;expr()-&gt;notIn('subs.id', $qb3-&gt;getDQL()))
      -&gt; setParameter('numemails1', $numemails);
  $rand_num = $qb2-&gt;getQuery()-&gt;getResult();
  
  $qb1 = $this-&gt;getEntityManager()-&gt;createQueryBuilder();
  $qb1-&gt; select('subss.id')
      -&gt; from('App\Entity\XX_Table', 'subss')
      -&gt; where('RAND() &lt; :sqbresult')
      -&gt; orderBy('RAND()')
      -&gt; setMaxResults($numemails)
      -&gt; setParameter('sqbresult', $rand_num);
  
  /*primary query to select users for future campaigns*/
  $qb = $this-&gt;getEntityManager()-&gt;createQueryBuilder();
  $qb -&gt; select('s')
      -&gt; from('App\Entity\XX_Table', 's')
      -&gt; where($qb-&gt;expr()-&gt;In('s.id', $qb1-&gt;getDQL()));
      //-&gt; where($expr-&gt;not($expr-&gt;exists($qb1-&gt;getDQL())));
  return $qb -&gt;getQuery() -&gt;getResult();
  </code></pre>
  
  <p>and I am trying to get the alternative of .sql code below to select random entities from DB that passed some basic criteria</p>
  
  <pre><code>SELECT 
  g.* FROM XX_table g
  JOIN
      (SELECT 
           id
       FROM
           XX_table
       WHERE
           RAND() &lt; (SELECT 
                      ((60000 / COUNT(*)) * 10) as rand_num
                     FROM
                      XX_table
                     WHERE 
                      id NOT IN (SELECT userID as id FROM YY_table emst WHERE CURDATE() - emst.datecreated &lt;=360)
                    )
       ORDER BY RAND()
       LIMIT 60000) AS z ON z.id= g.id
  </code></pre>
  
  <p>I have checked answers on here:
  <a href="https://stackoverflow.com/questions/44412692/too-few-parameters-the-query-defines-1-parameters-but-you-only-bound-0">Too few parameters: the query defines 1 parameters but you only bound 0</a>
  and here
  <a href="https://github.com/stwe/DatatablesBundle/issues/685" rel="nofollow noreferrer">https://github.com/stwe/DatatablesBundle/issues/685</a>
  and feel like solution is somewhere close but cannot get to it</p>