Improved Nested Queries In Cdbcriteria

$criteria=new CDbCriteria;		

$criteria->addCondition("active_to >= :active_to and 

job_id in(select distinct job_id from job_req_trade where trade_id 

    in (select trade_id from user_trade where registration_id=:registration_id))  ");

$criteria->params = array('registration_id'=>$reg_id, 'active_to' => date('Y-m-d'));

$dataProvider = new CActiveDataProvider('Job', array(



The above returns jobs matching a job seeker’s trades skills. How can I improve the above condition in CDbCriteria. it has double “IN”.


any suggestions please ?

For sql IN you should use


$criteria->addInCondition('some_id', array(1,2,3)); // default operator is AND 

$criteria2->addInCondition('another_id', array(1,2,3), 'OR'); //default operator is AND you can change to OR

Merge $critera and $criteria2: