Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add sub condition in where like (x=1 or y=1) and (z>0 and z<>1) #153

Open
kingofnull opened this issue Oct 5, 2016 · 1 comment

Comments

@kingofnull
Copy link

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?

@mrcnpdlk
Copy link

mrcnpdlk commented Oct 19, 2016

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants