codeigniter Query Structure Join Tables Using Query Builder


Sometimes we need to join multiple tables to get aggregate data in return. here is how we can achieve the same using CodeIgniter Query Builder / Active Records.

public function getStudentInfo($studentid){
    $query = $this->db->select(",, st.class, mk.maths,")
               ->from("students as st")
               ->join("marks as mk", "mk.student_id =", "inner")
               ->where("", $studentId)
    return $query->result();        

Here we use join() to join multiple tables and we can change join type in 3rd parameter like "inner", "left", "right" etc.