How to add condition with And as well as OR operator

I want to add conditions like that -

(Condition A) AND (Condition B OR Condition C)

How can I do this using addCondition??

use two CDbCriteria and mergeWith():

$criteria = new CDbCriteria();

$criteria->addCondition('condition A');

$criteria2 = new CDbCriteria();

$criteria2->addCondition('condition B');

$criteria2->addCondition('condition C', 'OR');


echo $criteria->condition; // (condition A) AND ((condition <img src='' class='bbc_emoticon' alt='B)' /> OR (condition C))

I didn’t know that. Interesting… Is the only way to do this using mergeWith?

You could simply just add both conditions inside the 2nd addCondition() call

$criteria = new CDbCriteria();

$criteria->addCondition('condition A');

$criteria->addCondition('condition B OR condition C');

Thanks a lot @georaldc

It’s too easy way to handle such types of conditions…