I have two tables users and assets and foreign key is user_id. I want users detail and count of each user’s asset So, I wrote query as below but not getting records. Please help me.
$users = $this->select()
->from(array('u' => 'users'),
array('firstname'))
->joinLeft(array('a' => 'assets'),
'u.id = a.user_id',
array('asset_per_user' => 'COUNT(a.id)'))
->group('u.id');
That mean
$thisis quite certainly a Zend_Db_Table in your example. By default select taken from a Zend_Db_Table cannot perform joins (as they are used for Active Record operation by default).Add:
And this merror essage will disappears. I’ve not checked the SQL query yet, it’s maybe right.