How to use joins in codeIgniter?

Today, We want to share with you join query with where condition in codeigniter.In this post we will show you multiple joins in codeigniter, hear for join query in codeigniter for two table we will give you demo and example for implement.In this post, we will learn about PHP Codeigniter 3 Multiple WHERE Conditions Example with an example.

Join Table Example Using Codeigniter

Codeigniter join where

$this->db->join('account_image', 'account_image.member_id =');
$this->db->where('', $id); 
$query = $this->db->get();

Will produce the query

// Select *from members join account_image on account_image.member_id = where = $id

use joins in codeigniter4/CI4

$machineInfoTable =  new ModMachineInfo();//creating the instance
            $data['catData'] = $machineInfoTable->distinct()->
                           mi_id,mi_slug,mi_name,mi_machine_condition,(select leveles.c_name from leveles where leveles.c_id=machine_info.machine_level) as levelName,
                ->where('machine_level IN (SELECT leveles.c_id from leveles where leveles.c_status = 1 and leveles.c_slug="'.$slug.'")')

Free Live Chat for Any Issue

joins/multiple joins with a group by in Codeigniter

$this->db->query("select shop1.ud_id,shop1.ud_date,shop1.up_lat_profit_date,shop1.ud_currency
                  ,sum(shop1.ud_amount*shop3.dp_percentage/100) as profit
               from shop1
               JOIN `shop2` ON `shop2`.`deposit_id` = `shop1`.`ud_id`
               JOIN `shop3` ON `shop3`.`dp_id` = `shop2`.`daily_profit_id`
               where `shop1`.`ud_status` = 1
               AND `shop3`.`dp_status` = 1
               AND `shop1`.`member_plan_id` = $up_id
               AND shop2.pr_status = 1
               group by shop1.ud_id");

use the WHERE clause

->join('messages','messages.member_id = members.m_id')
->join('city','city.member_id = members.m_id')

join more than two tables

->join('messages','messages.member_id = members.m_id')
->join('city','city.member_id = members.m_id')

right outer join in Codeigniter

->join('messages','messages.member_id = members.m_id','right')//this is the right join in codeigniter

left outer join

->join('messages','messages.member_id = members.m_id','left')//this is the left join in codeigniter

chaining (in Codeigniter)

->join('messages','messages.member_id = members.m_id')

I hope you get an idea about join query with where condition in codeigniter.
I would like to have feedback on my 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.

Rate this post