SHARE
TWEET

Untitled

a guest Jun 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT t1.* FROM tsg_message t1 INNER JOIN (
  2. SELECT chat_id, MAX(created_at) AS max_created_at FROM tsg_message GROUP BY chat_id
  3. ) t2
  4. ON t1.chat_id = t2.chat_id AND t1.created_at = t2.max_created_at
  5.      
  6. $subQuery = Message::find()
  7.             ->select(['chat_id', 'MAX(created_at) AS max_created_at'])
  8.             ->groupBy('chat_id');
  9.         $query = Message::find();
  10.         $query->alias('t1');
  11.         $query->innerJoin(['t2' => $subQuery], 't1.chat_id = t2.chat_id AND t1.created_at = t2.max_created_at');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top