title: CActiveDataProvider complex condition
body: <p>I have a table wall_messages with the following columns</p>
  
  <p>id<br>
  from_user_id<br>
  subject<br>
  message<br>
  date<br>
  message_reply_id</p>
  
  <p>I want to obtain a CActiveDataProvider with all the wall messages that have a given value for the _from_user_id_ column. So far so good.</p>
  
  <pre><code>        $outgoingMessages = new CActiveDataProvider ('Messages', array ( 
          'criteria' =&gt; array (
              'condition' =&gt; 'from_user_id ='.$userId-&gt;id,
          ), 
          'pagination' =&gt; array ( 
              'PageSize' =&gt; 5, 
          ) 
      ));
  </code></pre>
  
  <p>Now, I need to add the following condition: for those wall messages with matching _from_user_id_ value AND matching _message_reply_id_ value, I only want to keep one of those rows. Which one? The one with the "oldest" date. How can I do this? Im not good at all with sql queries so this is kind of hard for me. thanks!</p>
  
  <p>I came up with a temporary solution which is the extreme opposite of elegant:</p>
  
  <pre><code>    $sentMessages = array();
      $alreadyIncludedMessages = array();
  
      foreach ($user-&gt;messagesOut as $mess) {
          if (!in_array($mess-&gt;message_reply_id, $alreadyIncludedMessages)){
              $sentMessages[] = $mess;
              $alreadyIncludedMessages[]=$mess-&gt;message_reply_id;
          } 
      }
      $outgoingMessages = new CActiveDataProvider ('Messages', array ( 
          'pagination' =&gt; array ( 
              'PageSize' =&gt; 5, 
          ),
          'data'=&gt;$sentMessages
      ));
  </code></pre>