Yii Framework Forum: Improved Nested Queries In Cdbcriteria - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Improved Nested Queries In Cdbcriteria Rate Topic: -----

#1 User is offline   nguyendh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 21-March 11

Posted 27 May 2013 - 04:15 PM

$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(
	'criteria'=>$criteria,			
));


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

Thanks
I am new to Yii and this is my blog http://blog.michaelduy.com (deprecated hatadu.wordpress.com) about Yii, Git and PHP.
0

#2 User is offline   nguyendh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 21-March 11

Posted 03 June 2013 - 11:16 AM

any suggestions please ?
I am new to Yii and this is my blog http://blog.michaelduy.com (deprecated hatadu.wordpress.com) about Yii, Git and PHP.
0

#3 User is offline   aka 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 13-March 13

Posted 04 June 2013 - 06:29 AM

View Postnguyendh, on 03 June 2013 - 11:16 AM, said:

any suggestions please ?

For sql IN you should use

$criteria->addInCondition($column,$values,$operator='AND')

$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:

$criteria->mergeWith($criteria2);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users