You can use this query for this
SELECT tblSaler.SalerName, count(tblProduct.ProductID) as Total FROM tblSaler LEFT JOIN tblProduct ON tblProduct.SalerID = tblSaler.SalerID GROUP BY tblSaler.SalerID
And here is the active record for this
$select = array( 'tblSaler.SalerName', 'count(tblProduct.ProductID) as Total' ); $this->db ->select($select) ->from('tblSaler') ->join('tblProduct','roduct.SalerID = tblSaler.SalerID','left') ->group_by('tblSaler.SalerID') ->get() ->result_array();
Demo
OUTPUT
| SALERNAME | TOTAL | |-----------|-------| | sothorn | 1 | | Daly | 2 | | Lyhong | 3 | | Chantra | 1 |
source share