How to join tables in codeigniter

I this article we explain how to use joins in codeigniter active record query. using of codeigniter active record joins you can write complex join queries easily and also active record queries is safer and support all database because of codeigniter handle this automatically.

In codeigniter active record you can join multiple tables. here explain different type of join queries with example.

use join() method in active record for applying join on multiple tables, below show join() method parameters :

$this->db->join(TABLE_NAME, CONDITION, JOIN_TYPE); //JOIN_TYPE = left,inner,right and etc

If you leave third parameter codeigniter apply “INNER” join by default;

Normal Join with Single Table

Join With Where Clause Condition

Join with multiple tables and Where Clause conditions

As i previously mention if you want to apply any specific type of join please set third parameter in join() function.

Different types of Join(left, right, inner and etc)

in above join query i have apply INNER join on tbl_department table and LEFT join on tbl_plan.