how to used IN & Between Clause in YII ACtive Record?

后端 未结 7 1759
轻奢々
轻奢々 2021-02-14 10:15

I want write a Following Query in Active record .

SELECT *
FROM `User`
WHERE `UserId`
IN ( 6, 7, 8, 9 ) ;

Thanks

相关标签:
7条回答
  • 2021-02-14 10:52

    If you want to get your query faster, use Command Builder:

    Yii::app()->db->createCommand()
        ->select('*')
        ->from('user')
        ->where(array('in', 'UserId', array(6, 7, 8, 9)))
        ->queryAll();
    

    To get it via CActiveRecord, use findAllByAttributes

    User::model()
        ->findAllByAttributes(array(
             'UserId' => array(6,7,8,9)
        ));
    

    But it will get full object of User with all associated relations, so it's slower.

    0 讨论(0)
提交回复
热议问题