Nested subWhere's in complex where statements?
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?
Woow this really getting complicated @riseoflex88 , I suggest you use normal mySql query here
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()