pixie
pixie copied to clipboard
how to add sub condition in where like `(x=1 or y=1) and (z>0 and z<>1)`
how can i add sub conditions? for example I want generate a query like this:
SELECT filed FROM table where (x=1 or y=1) and (z>0 and z<>1)
how can i generate it?
I think that you should use code like this below:
$query = $this->oQuery
->table('table ')
->select('field')
->where(function ($q) {
$q->Where('x', '=', 1);
$q->OrWhere('y', '=', 1);
})
->where(function ($q) {
$q->Where('z', '>', 1);
$q->Where('z', '<>', 1);
});
$queryObj = $query->getQuery();
//$check = $query->get();
echo $queryObj->getRawSql();
And response:
SELECTfieldFROMtable WHERE (x= 1 ORy= 1) AND (z> 1 ANDz<> 1)