title: Get count query results via getSingleScalarResult() and groupBy() - exception
body: <p>I want get results of my query (with limit 10) + count possible results.
  I know there is similar questions and answers.</p>
  
  <p><a href="https://stackoverflow.com/questions/9214471/count-rows-in-doctrine-querybuilder#answer-9215880">for example here</a></p>
  
  <p>but if i trying get count possible rows (via <code>getSingleScalarResult()</code>) i will get excepton: <code>The query returned multiple rows. Change the query or use a different result function like getScalarResult().</code></p>
  
  <pre><code>    $query = $repository
          -&gt;createQueryBuilder('t')
          -&gt;select('COUNT(t.katId)', 't.hotel', 't.title', 't.desc', 'picture', 'MIN(t.price) AS price');
  
      $query-&gt;where('t.visible = (:visible)')-&gt;setParameter('visible', 1);
  
      // + some wheres, where in, more than....
  
      $query-&gt;groupBy('t.hotel');
      $query-&gt;setMaxResults(10);
  
      echo $query-&gt;getQuery()-&gt;getSingleScalarResult();
      exit();
  </code></pre>
  
  <p>I just need one integer whitch represent all results from my query.
  How can i get this count number? Ideal in one shot to db.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>if i remove <code>$query-&gt;groupBy('t.hotel');</code> and in select keep only <code>-&gt;select('count(t.katId)');</code> <strong>then it work</strong>.  But i need <code>groupBy</code> because it makes real count of results.</p>
  
  <hr>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>I divided it on two queries so - to get results i rolled back changes to state before trying any count information, and make clone this query (before set <code>setMaxResults</code> and <code>groupBy</code>), change select (keep all wheres) and get count information. </p>
  
  <p><strong>I will be grateful if someone offers better solution</strong></p>
  
  <ol>
  <li><p>Get results:</p>
  
  <ul>
  <li>removed COUNT() from select</li>
  <li>asking for results changed to 'normal' <code>-&gt;getArrayResults</code></li>
  </ul></li>
  <li><p>Get count:</p>
  
  <pre><code>$q = clone $query;
  
  $q-&gt;select('count(distinct t.hotel) as count');
  $r = $q-&gt;getQuery()-&gt;getArrayResult();
  
  echo $r[0]['count'];
  exit();
  </code></pre></li>
  </ol>