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

Nested subWhere's in complex where statements? #98

Open
riseoflex88 opened this issue May 3, 2018 · 2 comments
Open

Nested subWhere's in complex where statements? #98

riseoflex88 opened this issue May 3, 2018 · 2 comments

Comments

@riseoflex88
Copy link

I need to recreate this sql statement with the builder, but really struggling with creating a group of subwhere statements.

WHERE website_listing_priority IS NOT NULL
AND (
    (
        duration_magnitude <= 90 AND 
        duration_unit = 'Days'
     ) OR (
        duration_magnitude <= 12 AND 
        duration_unit = 'Weeks'
    ) OR (
        duration_magnitude <= 3 AND 
        duration_unit = 'Months'
    ) OR (
         duration_magnitude = 0 AND duration_unit = 'Years'
    )
)

Is there any way to handle this? Initially I thought I could do something like this

    $sql_ob->where()
        ->subWhere('OR')
            ->lessThanOrEqual('duration_magnitude', 90)
            ->lessThanOrEqual('duration_unit', 'Days')
        ->subWhere('OR')
            ->lessThanOrEqual('duration_magnitude', 12)
            ->lessThanOrEqual('duration_unit', 'Weeks')
        ->subWhere('OR')
            ->lessThanOrEqual('duration_magnitude', 3)
            ->lessThanOrEqual('duration_unit', 'Months')
        ->subWhere('OR')
            ->equals('duration_magnitude', 0)
            ->lessThanOrEqual('duration_unit', 'Years');

but this simply nests the subwhere's within each other e.g.

And (
Or (
Or (
Or (
)
)
)
)

How would I nest each of the subwhere's within the first Where statement?

@marcus-hiles
Copy link

Woow this really getting complicated @riseoflex88 , I suggest you use normal mySql query here

@usernotnull
Copy link

i faced a similar problem... subwheres are not helpful in complex queries, which anyone will have to encounter at some point.
In SQL it's easy to just add a parenthesis, the equivalent here would have been to have a method like beginGroup() and endGroup()

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

3 participants