join query with where condition in codeigniter

Today, We want to share with you left join in codeigniter.In this post we will show you join query in codeigniter controller, hear for codeigniter join 3 tables we will give you demo and example for implement.In this post, we will learn about How To Use Joins In CodeIgniter? with an example.

Codeigniter Inner Join With Multiple Tables

$this->db->select('*');
$this->db->from('members');
$this->db->join('profile_image', 'profile_image.member_id = members.id');
$this->db->join('city', 'city.member_id = members.id','left');
$this->db->join('post', 'post.member_id = members.id','left');
$this->db->join('friends', 'friends.member_id = members.id','left');
$this->db->where('members.id', $id); 
$query = $this->db->get();

Result

Select *from members
join profile_image on profile_image.member_id = members.id
left join city on city.member_id = members.id
left join post on post.member_id = members.id
left join friends on friends.member_id = members.id
where members.id = $id

codeigniter join 2 table data

<?php

$this->db->select('tamilrokers.name, infinityknow.something, mobile.another')
     ->from('table1 as tamilrokers')
     ->where('tamilrokers.id', $id)
     ->join('table2 as infinityknow', 'tamilrokers.id = infinityknow.id', 'LEFT')
     ->join('table3 as mobile', 'tamilrokers.id = mobile.id', 'LEFT')
     ->get();
?>

I hope you get an idea about delete 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.

Read Also:  insert Query In Codeigniter Example Tutorial

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  SQL LEFT OUTER JOIN overview and examples
  2. Read Also:  laravel try catch error handling (exception in controller)
  3. Read Also:  select Query In Codeigniter Example Tutorial
  4. Read Also:  Redirect HTTP To HTTPS Using Laravel Middleware
  5. Read Also:  how to pass array from view to controller?
  6. Read Also:  Laravel 6 Define Table Names in Model
  7. Read Also:  Update Query In Codeigniter Example Tutorial
  8. Read Also:  join query in codeigniter Example Tutorial
  9. Read Also:  Update query in codeigniter Example
  10. Read Also:  insert and display data from database in codeigniter
CLOSEX