Home > Back-end >  check if select count value is null/empty query builder symfony
check if select count value is null/empty query builder symfony

Time:12-03

My query builder looks like this

 $qb
            ->select([
                'c.id as c_id',
                'c.name as c_name',
                sprintf('(SELECT COUNT(t) FROM %s t WHERE t.example = c.example) as t_total',
                    t::class),
                sprintf('(SELECT COUNT(z) FROM %s z WHERE z.example = c.secondExample) as z_total',
                    z::class),
            ])
            ->from(c:class, 'c')
            ->getQuery()->getResult();

is there any way to check that t_total and z_total is null? I don't want show this row only if t_total AND z_total is null/empty

CodePudding user response:

as @mickmackusa say

$qb->having('z_total IS NOT NULL OR t_total IN NOT NULL');

works the way i wanted

  • Related