title: MySql Join Tables
body: <p>I have 3 tables,<br>
   jos_messages => 'message_id (PK)', 'message', 'from_user_id', 'touser id'</p>
  
  <p>jos_message_thread => 'thread_id PK','message_id FK', 'from_user_id', 'to_user_id'</p>
  
  <p>jos_users = > 'user_id(FK)', 'firstname', 'avatar'</p>
  
  <p>I need to make a query with this tables to return the data in one result, data are: 
  last inserted message (jos_messages), firstname and avatar of message sender (jos_users)
  the result should be something like this:</p>
  
  <p>message: "Hi, this is last inserted messsage"  </p>
  
  <p>firstname:"ledif"</p>
  
  <p>avatar:"http://a.com/a.png"</p>
  
  <p>What I have now is this query but the problem is, the returned message is not the last message inserted.</p>
  
  <pre><code>SELECT jmt.from_user_id, jm.message, ju.firstname, ju.avatar
  FROM jos_messages_thread AS jmt
  LEFT JOIN jos_messages AS jm ON jm.message_id = jmt.message_id
  LEFT JOIN jos_comprofiler AS ju ON ju.user_id =     jmt.from_user_id
  WHERE jmt.to_user_id ='$user_id'
  AND jmt.thread_owner ='$user_id'
  GROUP BY jmt.from_user_id
  </code></pre>
  
  <p>Is there a way to ORDER the jm.message_id in the middle of left join query? to make it something like:</p>
  
  <pre><code>LEFT JOIN jos_messages AS jm ON jm.message_id = (LAST INSERTED) jmt.message_id
  </code></pre>
  
  <p>Thanks!! btw Im not good in english, Im sorry if my question is not so clear.</p>