Codeigniter Inner Join With Multiple Tables

We can use following syntax to make inner join with multiple tables.

Codeigniter Inner Join With Multiple Tables

Using codeigniter standard query manager ($this->db->join) we can join with two or more than two tables. Here is syntax for Joins with Multiple Tables.

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

If you run the above example it will produce the following output.

// Result
Select *from users
join profile_image on profile_image.user_id = users.id
left join city on city.user_id = users.id
left join post on post.user_id = users.id
left join friends on friends.user_id = users.id
where users.id = $id


Advertisements

Add Comment

📖 Read More