A
A
AlexAll2020-05-01 17:12:33
Yii
AlexAll, 2020-05-01 17:12:33

How to correctly build a query in yii2 so that one record is taken from each category?

Here is the request:

$query = self::find()->select('id, title, url, img, img_thumb, website_id')->where(['status' => 1])
                ->andWhere(['in', 'website_id', $array_websites])->limit($sum)->orderBy(new Expression('rand()'))->asArray()->all();

$array_websites - here are 10 IDs of different categories, it is necessary that the selection be one entry from each category.
What's the best way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question