Yii Framework Forum: Yii criteria group and order - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii criteria group and order Rate Topic: -----

#1 User is offline   Aneesh Asokan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 254
  • Joined: 26-September 12

Posted 27 February 2018 - 04:32 AM

Hi
How we can fetch last data (in descending order data fetch) after group and order? I fetch the data with the following code and its return the first data after order. I need to fetch from last.

$criteria   =   new CDbCriteria;                
$criteria->condition= 'from_user=:user OR to_user=:user';
$criteria->params= array(':user'=>  Yii::app()->user->id);                       
$criteria->group= 'chat_id';
$criteria->order= 'created_at DESC'; 


Using this sql, it returns correct way
SELECT * FROM ( SELECT * FROM `chat_messages` ORDER BY `created_at` DESC ) AS tmp_table GROUP BY `chat_id` 

Thanks
Aneesh
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users