Easily retrieve and organize data in CodeIgniter 4 using our guide on utilizing Query Builder's 'group by' along with 'where'. Optimize your data fetching process efficiently. Query grouping allows you to create groups of WHERE clauses by enclosing them in parentheses. This will allow you to create queries with complex WHERE clauses. Nested groups are supported. We can group our query in a where clause. Green data filter is easily done from group.
public function group_query()
{
$query = $this->seller
->table('users')
->select('*')
->where('age','20')
->groupStart()
->where('salary',200)
->groupEnd()
->get();
echo "<pre>";
print_r($query->getResult());
}
public function group_query()
{
$query = $this->seller
->table('users')
->select('*')
->where('age','20')
->groupStart()
->where('salary',200)
->where('id',29)
->groupEnd()
->where('name','deepak Tailor')
->get();
echo "<pre>";
print_r($query->getResult());
}
If we want to do more operators in the group, we can do it with orGroupStart ().
public function group_query()
{
$query = $this->seller
->table('users')
->select('*')
->where('age','20')
// first group start
->groupStart()
->where('salary',200)
// second group start
->orGroupStart()
->where('salary',4000)
->groupEnd()
// second group close
->groupEnd()
// first group close
->get();
echo "<pre>";
print_r($query->getResult());
}
public function group_query()
{
$query = $this->seller
->table('users')
->select('*')
->where('age','20')
// first group start
->notGroupStart()
->where('salary',200)
->groupEnd()
// first group close
->get();
echo "<pre>";
print_r($query->getResult());
}
public function group_query()
{
$query = $this->seller
->table('users')
->select('*')
->where('age','25')
// second group start
->orNotGroupStart()
->where('salary',4000)
->groupEnd()
// second group end
->get();
echo "<pre>";
print_r($query->getResult());
}
My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in