Yii Framework Forum: Query - Yii Framework Forum

Jump to content

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

Query

#1 User is offline   n-r 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 222
  • Joined: 19-April 13

Posted 03 May 2013 - 11:33 PM

hello
Sorry ,
i have 2 table that Were joined together.
now want Recordes that NOT In Join result.
how??
$a=  User::model()->with('tels')->findAll());

i want SID users that not in $a.
thank you!
0

#2 User is offline   sarthak 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 19-December 12
  • Location:Ahmedabad, Gujarat, India

Posted 04 May 2013 - 12:00 AM

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
0

#3 User is offline   n-r 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 222
  • Joined: 19-April 13

Posted 04 May 2013 - 12:35 AM

View Postsarthak, on 04 May 2013 - 12:00 AM, said:

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
0

#4 User is offline   Aashis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 18-March 12

Posted 04 May 2013 - 02:59 AM

View Postn-r, on 04 May 2013 - 12:35 AM, said:

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(
  'select'=>array('*'),
  'condition'='SID NOT IN (:id)',
  'params'=>array(':id'=>$a['sid'])
));


keep trying and there may be some mistake in my code, bcoz i haven't tried it..
just guessing
0

#5 User is offline   Yii Developer India 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 18-December 11
  • Location:Mumbai, India

Posted 22 May 2013 - 10:14 AM

Hello,

Try

$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()
->select('*')
->from('tbl_user u')
->join('tbl_tels t', 'u.sid=t.sid')
->where('id!=:id', array(':id'=>$id))
->queryAll();

Check this link : http://www.yiiframew...e.query-builder
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