I have two table as follow:
- tblSaler
SalerID | SalerName |
----------------------|
1 | sothorn |
----------------------|
Please try this code. Its working fine for me and it will help you also.
$this->db->select('SalerName, count(*)');
$this->db->from('tblSaler');
$this->db->join('tblProduct', 'tblSaler.SalerID = tblProduct.SalerID');
$this->db->group_by('tblSaler.SalerID');
$query = $this->db->get();
You can get whole SQL query using this line below
$query = $this->db->get();
echo $this->db->last_query();