Reputation: 101
I am beginner in using codeigniter query builder class. and I got a problem in converting this query using query builder class.
SELECT tb_country.`countryName`, COUNT(tb_country.countryId) AS totalCustomer FROM tb_customer
JOIN tb_city ON tb_city.`cityId` = tb_customer.`cityId`
JOIN tb_state ON tb_state.`stateId` = tb_city.`stateId`
JOIN tb_country ON tb_country.`countryId` = tb_state.`countryId`
GROUP BY tb_country.`countryName`
any answers will be helpful to me, thanks in advance!
Upvotes: 0
Views: 279
Reputation: 496
$this->db
->select("tb_country.countryName, COUNT(tb_country.countryId) AS totalCustomer", false)
->from('tb_customer')
->join('tb_city', 'tb_city.cityId = tb_customer.cityId')
->join('tb_state', 'tb_state.stateId = tb_city.stateId')
->join('tb_country', 'tb_country.countryId = tb_state.countryId')
->group_by('tb_country.countryName')
->get()
->result();
Upvotes: 1