2

I'm trying to run a custom query on my DB with Doctrine2 using the following:

$qb = $em->createQueryBuilder();
        $qb->select(array('c', 'count(uc) as numMembers'))
           ->from('AcmeGroupBundle:Group', 'c')
           ->leftJoin('c.members', 'uc', 'WITH', 'uc.community = c.id')
           ->groupBy('c')
           ->orderBy('numMembers', 'DESC')
           ->setFirstResult( $offset )
           ->setMaxResults( $limit );
        $entities = $qb->getQuery()->getResult();

This query runs flawlessly on my local MySQL DB. But when I try to run it against my production DB (MSSQL), i get the following error:

SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Column 'Group.discr' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

I do have a discriminator column because I have classes inheriting from Group. Any suggestions on how should I change the query to make it compatible with MSSQL?

Thanks!

pmmaga
  • 410
  • 7
  • 18
  • Don't know if this will help you, this explanation worked for me : http://stackoverflow.com/questions/13999817/reason-for-column-is-invalid-in-the-select-list-because-it-is-not-contained-in-e – l1sq0u48 Mar 04 '14 at 14:51

0 Answers0