Answer the question
In order to leave comments, you need to log in
Pagination in yii2 with data grouping, displays the wrong amount?
There is such a complex query with data grouping and a temporary table
$subQuery = (new \yii\db\Query())
->from('pm')
->where('user_id = :user_id AND sender_id != :user_id AND status != :status ' . $w . '
ORDER BY created_at DESC', [
'user_id' => Yii::$app->user->id, 'status' => Pm::STATUS_DELETE]);
$query = self::find()->select('id, text, created_at, username, sender_id, user_id, sum(unread) as noread');
$query->from(['AS `tmp_table` GROUP BY `sender_id` ' => $subQuery]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question