yii活动记录NOT IN查询

时间:2013-08-10 14:23:36

标签: yii cactivedataprovider

我们如何在yii

中为此查询实现CActive Record
SELECT * 
FROM location WHERE locationid NOT IN 
( SELECT location 
  FROM memberlocation
  WHERE memberid = 2371)

1 个答案:

答案 0 :(得分:3)

试试这个

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

或者你可以做这样的事情

 $result= Location::model()->findAll(array(
                        'select'=>'*',
                        'condition'=>'locationid NOT IN( SELECT location 
      FROM memberlocation
      WHERE memberid = :member_id)',
                        'params'=>array(':member_id'=2371)
                    ));