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

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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