php - zend left join count not working -
ia have problem count in multi joins
$query = $this->select() ->setintegritycheck(false) ->from(array('u' => 'users')) ->join(array('c' => 'clients'), 'u.id = c.user_id', 'count(c.user_id) clientscount') ->join(array('emails' => 'u_emails'), 'u.id = emails.user_id', 'count(emails.user_id) emailscount') ->join(array('sms' => 'u_sms'), 'u.id = sms.user_id', 'count(sms.user_id) smscount') ->where('u.id=?', (int) user_id)->group('u.id');
i think can out of problem:
$this->select() ->from(array('u' => 'users'), array( 'clientscount' => new zend_db_expr("(select count(*) clients clients.user_id = u.id)"), 'emailscount' => new zend_db_expr("(select count(*) emails emails.user_id = u.id)"), 'smscount' => new zend_db_expr("(select count(*) sms sms.user_id = u.id)"), ) ->where('u.id=?', (int) user_id) ->group('u.id');
i can't test query feel free ask if have problems.
edited answer, please try again
Comments
Post a Comment