Sorry ,

i have 2 table that Were joined together.

now want Recordes that NOT In Join result.


$a=  User::model()->with('tels')->findAll());

i want SID users that not in $a.

thank you!

By this join, we have those records that foreign key of user table in tels table.

and if you want records that not contain $a then

you have to first take whole SID array from $a and then according to that you have to find SID from User

mercy ;D

normal sql querry should be like this:

select * from USer where sid NOT IN($a[‘sid’]

in controller u will have to write something like this

$model= User::model()->finAll(array(


  'condition'='SID NOT IN (:id)',



keep trying and there may be some mistake in my code, bcoz i haven’t tried it…

just guessing



$a= User::model()->with(‘tels’)->findAll(array(‘condition’=‘SID NOT IN (:id)’,‘params’=>array(’:id’=>$a[‘sid’])));

OR write custom query :

$a = Yii::app()->db->createCommand()


->from('tbl_user u')

->join('tbl_tels t', 'u.sid=t.sid')

->where('id!=:id', array(':id'=>$id))


Check this link : http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder