SqlQuery: Is it possible to group where and orWhere clauses separately?

33 views
Skip to first unread message

Corey Taylor

unread,
Apr 11, 2017, 9:12:22 PM4/11/17
to The Aura Project for PHP
I was trying to find a way to specify groups of where clauses together where the SQL would look something like:

where (condition AND condition) OR (condition)

So far, I only see how to specify AND where and OR where clauses that chain together.

corey

Paul Jones

unread,
Apr 11, 2017, 9:16:44 PM4/11/17
to aur...@googlegroups.com
Hi Corey,

In SqlQuery 2.x, you can try something like this:

$select->where('(condition1 AND condition2)')
->orWhere('(condition3)');

In 3.x, we have added condition-grouping via closures:

$select->where(function ($select) {
$select->where('condition')
->where('condition');
})->orWhere(function ($select) {
$select->where('condition3');
});

Does that help?


--
Paul M. Jones
pmjo...@gmail.com
http://paul-m-jones.com

Modernizing Legacy Applications in PHP
https://leanpub.com/mlaphp

Solving the N+1 Problem in PHP
https://leanpub.com/sn1php



Corey Taylor

unread,
Apr 16, 2017, 10:25:07 AM4/16/17
to The Aura Project for PHP
Yes, I believe that should work for me, thanks!

corey
Reply all
Reply to author
Forward
0 new messages