I am working with mysql with codeigniter, hHere is my table structure:
Table A:
id(doctorid) name
-----------------------------
1 abc
2 xyz
3 ahd
4 djd
Table B:
id doctor_id type
-------------------------------------
1 1 Nuter
2 3 Spay
Now I want to get all records of doctor with count of type, I want the following result:
id name Nuter Spay
---------------------------------------
1 abc 1 0
2 xyz 0 Spay
I tried with following code but not working for me, how can I do this ?
$this->db->select('A.*');
$this->db->from('A');
$this->db->join('B', 'B.doctor_id = (SELECT COUNT(Type) FROM B )');
$query = $this->db->get();