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.

Read Also:  join query with where condition in codeigniter

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.

Read Also:  How to Create dynamic Responsive Image/photo gallery in php?

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

Read Also:  sql left outer join

$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. Read Also:  PHP Laravel Remove Brackets Example
  2. Read Also:  PHP Laravel 7 Inner Join Query Example (join query in laravel)
  3. Read Also:  sql join multiple tables
  4. Read Also:  Laravel 7 Custom Pagination View Example Tutorial
  5. Read Also:  how to call javascript function in html & JavaScript Define
  6. Read Also:  How to get WooCommerce order details using wc_order?
  7. Read Also:  get last query codeigniter | last query in ci Example
  8. Read Also:  How to Decode JSON Data in PHP?
  9. Read Also:  joins in sql
  10. Read Also:  sql join multiple tables with conditions
CLOSEX