Answer the question
In order to leave comments, you need to log in
Sql Query with temporary table in ActiveDataProvider?
I need to insert such a Sql query into ActiveDataProvider, tell me how?
SELECT * FROM (
SELECT id, username, text, sender_id
FROM pm
WHERE user_id =2 AND sender_id !=2 AND STATUS !=2
ORDER BY created_at DESC
) AS tmp_table GROUP BY sender_id
Answer the question
In order to leave comments, you need to log in
How big is the need for a temporary table in such a query, but if there really is such a need, then you can insert it into the CSqlDataProvider
Here is a request
$subQuery = (new Query())->select('id, username, text, sender_id')->from('pm')->where('user_id =2 AND sender_id !=2 AND STATUS !=2 ORDER BY created_at DESC');
$query = self::find();
$query->from(['AS tmp_table GROUP BY sender_id' => $subQuery]);
$query->with(['profile']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question