title: How to get Last Message from chat conversation?
body: <p>Hi i have a table name <code>messages</code> i want to get last message from chat conversation between two users.</p>
  
  <p>Table - </p>
  
  <pre><code>id  from_id   to_id    text     created
  ========================================
  1      1        2     hi        2014-12-01 10:30:10
  2      2        1     Hello     2014-12-01 10:30:20
  3      3        1     Hi chinu  2014-12-01 10:32:02
  4      3        1     hw r u?   2014-12-01 10:32:22
  5      2        1     h r u?    2014-12-01 10:33:01
  </code></pre>
  
  <p>Please check my query = </p>
  
  <pre><code>//$user_id=$this-&gt;Session-&gt;read('Auth.User.id');
  $user_id=1;
  $fields=array('DISTINCT(Message.from_id), Message.id, Message.text, Message.created');
  
      $this-&gt;Paginator-&gt;settings = array(
              'conditions'=&gt;array('Message.to_id'=&gt;$user_id),
              'limit' =&gt; 30,
              'order' =&gt; array(
                  'Message.created' =&gt; 'DESC',
                  'Message.id' =&gt; 'DESC'
              ),
              'fields'=&gt;$fields,
              'group'=&gt;array('Message.from_id')
      );
      $inbox = $this-&gt;Paginator-&gt;paginate('Message');
      pr($inbox);
      $this-&gt;set('inbox', $inbox);
  </code></pre>
  
  <p>I want to get last message conversation between 2 and 3 id. The output looks like - </p>
  
  <pre><code>id  from_id   to_id    text     created
  ========================================
  5      2        1     h r u?    2014-12-01 10:33:01
  4      3        1     hw r u?   2014-12-01 10:32:22
  </code></pre>
  
  <p>Please help me. If you don't know the cakephp please post core php MySQL query here.</p>
  
  <p>Thanks
  chatfun</p>