I'm trying to retrieve a number of rows with unique uids.
$qb->select('COUNT() as cnt')
->from($type, 'c')
->groupBy('c.organization, c.process_role, c.domain, c.year')
->getQuery()->getSingleScalarResult()
But it returns an array of group counts. How should I write this correct?
Finally, that works, but it's kinda ugly
$count = $this->_em->createQuery( 'SELECT COUNT(c.id) FROM '.$type.' as c WHERE c.id IN ('
. 'SELECT c1.id FROM ' . $type . ' c1 '
. 'GROUP BY c1.organization, c1.process_role, c1.domain, c1.year)')
->getSingleScalarResult();
Try breaking up your single
groupBy
intoaddGroupBy
functions:However this does in fact return the same thing since it will just group results into unique sets by those 4 variables. You should instead use a
DISTINCT
selection method and count the resulting rows.This is the only known method to me that will work since DQL won't support any alternative strategies (such as
SELECT COUNT(*) FROM (SELECT DISTINCT ... )
)Insted of
$qb->select();
use$qb->distinct();
. I hope it works.