Query builder - group by with where in codeigniter 4 - deesoft service

Query builder - group by with where in codeigniter 4

Deepak Tailor Image
Deepak Tailor - Nov 17 2020
Query builder - group by with where in codeigniter 4

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.

Single where Condition
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());
}
Multiple where condition
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());
}
orGroupStart() in query

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());
}
notGroupStart in query
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());
}
orNotGroupStart in query
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());
}
Deepak Tailor Image
Deepak Tailor

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