join query in codeigniter Example Tutorial

Today, We want to share with you join query in codeigniter Example Tutorial.In this post we will show you joins in codeigniter, hear for join two tables in codeigniter we will give you demo and example for implement.In this post, we will learn about join three tables in codeigniter with an example.

join query in codeigniter Example Tutorial

There are the Following The simple About join same table in codeigniter Full Information With Example and source code.

As I will cover this Post with live Working example to develop joins table query in codeigniter, so the joins query with where condition in codeigniter is used for this example is following below.

also you can read my prev Post Like as self join, left join, multiple joins, sql join multiple tables, with codeigniter join 2 tables, and join 3 tables in codeigniter as well as Join with multiple tables.

CodeIgniter – Join Query

CodeIgniter Joins tutorial – How to use Inner Join Clause, Left Join / Right Join Clause, Cross Joins Clause, Advanced Joins Clauses, Sub-Query Joins etc.

CodeIgniter Joins query function is used to retrive the data result from multiple Database tables. The joins types are MySQL normal joins, inner joins, left joins as well as right joins.

join query in codeigniter Example Tutorial
join query in codeigniter Example Tutorial

How to JOIN Tables in Codeigniter

Hear we are use join() method to join 2 Database table or more then 2 database tables in codeigniter model.we are using join() method for Normal Joins, Joins With Condition, Joins with multiple tables and Joins with specific type Query likeleft, right, inner, outer, right outer, left outer.

Normal Join

$this->db->select('tbl_member.membername,tbl_member.memberid,tbl_membertype.typee');
$this->db->from('tbl_member');
$this->db->join('tbl_membertype','tbl_membertype.membertypeid=tbl_member.membertypeid');
$query=$this->db->get();
$data=$query->result_array();

SELECT `tbl_member`.`membername`, `tbl_member`.`memberid`, `tbl_membertype`.`type` 
FROM (`tbl_member`) 
JOIN `tbl_membertype` ON `tbl_membertype`.`membertypeid`=`tbl_member`.`membertypeid`

Join With Condition

$this->db->select('tbl_member.membername,tbl_member.memberid,tbl_membertype.typee');
$this->db->from('tbl_member');
$this->db->join('tbl_membertype','tbl_membertype.membertypeid=tbl_member.membertypeid');
$this->db->where('tbl_membertype','admin');
$query=$this->db->get();
$data= $query->result_array();

SELECT `tbl_member`.`membername`, `tbl_member`.`memberid`, `tbl_membertype`.`type` 
FROM (`tbl_member`) 
JOIN `tbl_membertype` ON `tbl_membertype`.`membertypeid`=`tbl_member`.`membertypeid`

Inner Join

Example : 1

Used Two MySQL Database table Inner Join in codeigniter

$this->db->select('tbl_member.membername,tbl_member.memberid,tbl_membertype.type');
$this->db->from('tbl_member');
$this->db->join('tbl_membertype','tbl_membertype.membertypeid=tbl_member.membertypeid','inner');
$query=$this->db->get();

SELECT `tbl_member`.`membername`, `tbl_member`.`memberid`, `tbl_membertype`.`typee` 
FROM (`tbl_member`) 
INNER JOIN `tbl_membertype` ON `tbl_membertype`.`membertypeid`=`tbl_member`.`membertypeid`

Example : 2

Used Three MySQL Database table Inner Join in codeigniter

$this->db->select('membername,amount, configdescription');
$this->db->from('tbl_member');
$this->db->join('tbl_memberplan','tbl_memberplan.memberid=tbl_member.memberid','inner');		
$this->db->join('tbl_plan',
            'tbl_memberplan.plan_config_id=tbl_plan.configid','inner');

SELECT `membername`, `amount`, `configdescription` 
FROM (`tbl_member`) 
INNER JOIN `tbl_memberplan` ON `tbl_memberplan`.`memberid`=`tbl_member`.`memberid` 
INNER JOIN `tbl_plan` ON `tbl_memberplan`.`plan_config_id`=`tbl_plan`.`configid`

Left Join

Used Two MySQL Database table Left Join in codeigniter

$this->db->select('tbl_member.membername,tbl_member.memberid,tbl_membertype.type');
$this->db->from('tbl_member');
$this->db->join('tbl_membertype','tbl_membertype.membertypeid=tbl_member.membertypeid','Left');
$query=$this->db->get();

SELECT `tbl_member`.`membername`, `tbl_member`.`memberid`, `tbl_membertype`.`typee` 
FROM (`tbl_member`) 
Left JOIN `tbl_membertype` ON `tbl_membertype`.`membertypeid`=`tbl_member`.`membertypeid`

Right Join

Used Two MySQL Database table Right Join in codeigniter

$this->db->select('tbl_member.membername,tbl_member.memberid,tbl_membertype.type');
$this->db->from('tbl_member');
$this->db->join('tbl_membertype','tbl_membertype.membertypeid=tbl_member.membertypeid','Right');
$query=$this->db->get();

SELECT `tbl_member`.`membername`, `tbl_member`.`memberid`, `tbl_membertype`.`typee` 
FROM (`tbl_member`) 
Right JOIN `tbl_membertype` ON `tbl_membertype`.`membertypeid`=`tbl_member`.`membertypeid`

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about update joins query in codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Codeigniter delete query from Database
  2.   codeigniter print last query - PHP Examples
  3.   how to pass array from view to controller?
  4.   Laravel 6 Set Active Navigation Menu Example
  5.   WordPress Plugin Activation Dependency Check
  6.   Update query in codeigniter Example
  7.   PHP Jquery Ajax CRUD Example Tutorial From Scratch
  8.   PHP Google No CAPTCHA reCAPTCHA jQuery Ajax
  9.   insert Query In Codeigniter Example Tutorial
  10.   delete Query In Codeigniter Example Tutorial
Tags:, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,