In this article, we will discuss about how to use Join query in the CodeIgniter framework(CodeIgniter join query example). what Join Query? if you need two or more tables data then we can easily get data using the Join query.
join query is the specific type available like left join, right join, outer join, inner join, left outer join, and right outer join.
The join query method is used to fetch data into two or more tables.
$this->db->select('*')
->from('product')
->join('category','category.id = product.category_id')
->get();
The left join query method is used to return all rows data into the left table and return the equal rows of data into the right table.
$this->db->select('*')
->from('product')
->join('category','category.id = product.category_id','left')
->get();
The right join query method is used to return all rows data into the right table and return the equal rows data into the left table.
$this->db->select('*')
->from('product')
->join('category','category.id = product.category_id','right')
->get();
The Inner join query method is used to return matching row data into both tables.
$this->db->select('*')
->from('product')
->join('category','category.id = product.category_id','inner')
->get();
The Outer join query method is used to return all rows of data to both tables.
$this->db->select('*')
->from('product')
->join('category','category.id = product.category_id','outer')
->get();
The left outer join query method is used to return all rows of data into the left table and return the equal rows of data into the right table.
$this->db->select('*')
->from('product')
->join('category','category.id = product.category_id','left outer')
->get();
The right outer join query method is used to return all rows of data into the right table and return the equal rows of data into the left table.
$this->db->select('*')
->from('product')
->join('category','category.id = product.category_id','right outer')
->get();