I want to get user highest education details in descending order instead of all education details, so I am joining user table with education details table, but query which I written using group by and order by clause even it is not working as per my expectation.
table users:
id name
1 aaa
2 bbb
3 ccc
table education_details
eid user_id course_id course type
1 1 12 graduation
2 1 13 post_graduation
3 2 18 graduation
4 2 20 post_graduation
Expected output:
user_id eid course_type
2 4 post_graduation
1 2 post_graduation
Query:
$this->db->select('u.id as user_id,e.eid,e.course_type');
$this->db->from('users u');
$this->db->join('education_details e','e.user_id=u.id','left');
$this->db->order_by('e.id','desc');
$this->db->group_by('e.user_id');
$this->db->get()->result();