Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

yii

I want write a Following Query in Active record .

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

Thanks

like image 476
Kaletha Avatar asked May 20 '11 05:05

Kaletha


People also ask

How do we use in?

How to Use In. The function of in as a preposition is to indicate something is inside something else or, more abstractly, to measure time. It is used when you want to indicate a position within a general space.

WHY IS IN USED?

In general, in is used to indicate location or position within or inside something: We went for a swim in the lake. They have a house in the country. Albuquerque is in New Mexico.


1 Answers

You can use CDbCriteria statement:

$criteria = new CDbCriteria();
$criteria->addInCondition('userId', array(6,7,8,9));
$result = User::model()->findAll($criteria);
like image 178
Aleksy Goroszko Avatar answered Oct 06 '22 17:10

Aleksy Goroszko