title: Yii: how to ORDER BY before GROUP BY with CDbCriteria?
body: <p>With a query like this one:</p>
  
  <pre><code>SELECT * FROM (
      SELECT * FROM message ORDER BY added_on DESC
  ) as m WHERE receiver_id = 2 GROUP BY sender_id ORDER BY priority_id DESC;
  </code></pre>
  
  <p>I know how to do it using <code>findAllBySql</code>:</p>
  
  <pre><code>$this-&gt;findAllBySql(
      'SELECT * FROM (
          SELECT * FROM message ORDER BY added_on DESC
       ) as m WHERE receiver_id = :receiverId 
       GROUP BY sender_id 
       ORDER BY priority_id DESC', 
       array('receiverId' =&gt; $userId));
  </code></pre>
  
  <p>But I was wondering if there is any way to do this using <a href="http://www.yiiframework.com/doc/api/1.1/CDbCriteria">CDbCriteria</a> cause the following code, of course, doesn't work:</p>
  
  <pre><code>$criteria = new CDbCriteria();
  $criteria-&gt;condition = 'receiver_id = :receiverId';
  $criteria-&gt;group = 'sender_id';
  $criteria-&gt;order = 'priority_id DESC, added_on DESC';
  $criteria-&gt;params = array('receiverId' =&gt; $userId);
  </code></pre>
  
  <p>Thanks.</p>