Question

How can we implement CActive Record for this query in yii

SELECT * 
FROM location WHERE locationid NOT IN 
( SELECT location 
  FROM memberlocation
  WHERE memberid = 2371)
Was it helpful?

Solution

Try this

$sql='SELECT * 
FROM location WHERE locationid NOT IN 
( SELECT location 
  FROM memberlocation
  WHERE memberid = 2371)';
$result = Yii::app()->db->createCommand($sql)->queryAll();

Or you could do something like this

 $result= Location::model()->findAll(array(
                        'select'=>'*',
                        'condition'=>'locationid NOT IN( SELECT location 
      FROM memberlocation
      WHERE memberid = :member_id)',
                        'params'=>array(':member_id'=2371)
                    ));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top