How to create grouped WHERE

33 views
Skip to first unread message

Mário Pálka

unread,
Jun 8, 2017, 5:40:50 AM6/8/17
to NotORM
Hello,

how would you transform this SQL query into NotORM?

SELECT * FROM items WHERE (column1 > 0 AND column2 > 0) OR (column3 < 0 AND column4 < 0);

It's just dummy example, where I want to ask for AND and OR grouped by brackets.

Thank you

Allysson David

unread,
Jun 8, 2017, 10:41:15 AM6/8/17
to not...@googlegroups.com
AFAIK, each call to WHERE, AND and OR will result in a "cell condition", so you could do it like this:

$db->items()->where("column1 > ? AND column 2 > ?", array(0, 0))->or("column3 < ? AND column4 < ?", array(0, 0));

Or even like this:

$db->items()->where("(column1 > ? AND column 2 > ?) OR (column3 < ? AND column4 < ?)", 0, 0, 0, 0);

Note: Parameters could be either arrays or not. 

--
You received this message because you are subscribed to the Google Groups "NotORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to notorm+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mário Pálka

unread,
Jun 15, 2017, 5:19:54 AM6/15/17
to NotORM
Thank you for your advice!
To unsubscribe from this group and stop receiving emails from it, send an email to notorm+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages