title: DQL: groupBy suborders per webstore
body: <p>I am trying to create a query that gives me all the items sold since the last time this funcion was called upon. Those items will then be sorted per webstore and they receive an email stating what what they sold that day. I also want to give this opportunity to so called categories, which these webstores can join. a category get his own "webstore" so that in our case we can easily access order and other functions, which are similair. So that they can get an email showing items that have been sold across all webstores. </p>
  
  <p>This i then want to display twig, which will then be converted to pdf and send as an attachment and emailed. This I all pretty much have working. The issue I have is making it so that I can take the items in the suborders and display them per webstore.</p>
  
  <p>webstore1:
     pizza    x2
     burgers  x3</p>
  
  <p>webstore2:
    cheese x2
    pizza x2</p>
  
  <pre><code>    public function getWebstoresBatch($latestDate)
  {
      $em=$this-&gt;getDoctrine()-&gt;getManager();
      $webstoreRepository = $em-&gt;getRepository(BaseController::WEBSTORE_REPOSITORY);
  
      $q = $webstoreRepository-&gt;createQueryBuilder('w')
          -&gt;select('w, s, o' )
          -&gt;setParameter('latestDate', $latestDate)
          -&gt;innerJoin('w.sales', 's')
          -&gt;where('w.sendBatchMail = true')           
          -&gt;andWhere("s.date &gt;= :latestDate");
  
          if('w.subscription_type == 4'){ //if webstore is a category-webstore
              $q-&gt;innerJoin('s.subOrders', 'o')
              -&gt;innerJoin('o.webstore', 'ew') 
              -&gt;groupBy('ew.name');
          }
  
      $q = $q-&gt;getQuery();
  
      $res = $q-&gt;getResult();
  
      return $res;
  }
  </code></pre>
  
  <p>I try to do this all with 1 query in the hope not to have to much duplicate code. But I am stuck at this stage. Whenever I try to run this I get the following error regarding the groupBy:</p>
  
  <pre><code>SQLSTATE[42803]: Grouping error: 7 ERROR: column "r0_.id" must appear in the GROUP BY clause or be used in an aggregate function
  LINE 1: SELECT r0_.id AS id_0, r0_.name AS name_1, r0_.description A.
  </code></pre>
  
  <p>I do not know for certain if what I am trying is even possible this way, if I should just make it 2 functions or 2 queries I will do that.</p>