CodeIgniter 4 Join 2, 3, 4 Tables

CodeIgniter 4 Join 2, 3, 4 Tables

CodeIgniter join 2,3,4 or multiple tables example. Through this tutorial, you will learn how to join 2,3,4, or multiple tables for fetching/getting data from database tables in codeIgniter 4 using join query builder with multiple where clauses.

If you want to join two or multiple tables in codeigniter to fetch data from multiple tables using join clause. So, this tutorial is for you.

CodeIgniter 4 Join 2,3,4 Tables Example

CodeIgniter JOIN query builder clause returns all rows from both table, if there are matches in the both table. Otherwise, the result is NULL. Let’s see the example of query builder join codeigniter 4:

  • Example 1: Codeigniter 4 join 2 Tables
  • Example 2: Codeigniter 4 join 3 Tables
  • Example 3: CodeIgniter 4 Join() with Multiple Conditions

Example 1: Codeigniter 4 join 2 Tables

Here, fetch data using Codeigniter query builder join(), you can see the following example:

$builder = $db->table('cities');
$builder->select('*');
$builder->join('cities', 'cities.country_id = country.id', 'left');
$query = $builder->get();

Example 2: Codeigniter 4 join 3 Tables

In this example, get data using codeigniter query builder join 3 table, you can see the following example:

$builder = $db->table('cities');
$builder->select('*');
$builder->join('states', 'states.country_id = country.id', 'left');
$builder->join('cities', 'cities.country_id = country.id', 'left');
$query = $builder->get();

Example 3: CodeIgniter 4 Join() with Multiple Conditions

In this example, get data using Codeigniter query builder join with multiple where conditions, you can see the following example:

$builder = $db->table('cities');
$builder->select('*');
$builder->join('states', 'states.country_id = country.id', 'left');
$builder->join('cities', 'cities.country_id = country.id', 'left');
$builder->where('country.status', 'active');
$builder->where('states.status', 'active');
$builder->where('cities.status', 'active');
$query = $builder->get();

Conclusion

CodeIgniter query builder join() example tutorial, you have learned how to use codeIgniter query buider join() to join 2, 3, or multiple tables with multiple conditions.

Recommended Codeigniter Posts

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *