title: How to select messages from two different tables in a specific order with Mysql?
body: <p>There are totally five data tables:</p>
  
  <pre><code>theUser (*id*, name)
  theGroup (*id*, name)
  Membership (*group_id*, *user_id*)
  gpMsge (*id*, sender, receiver, content, time)  # message within group
  idMsge (*id*, sender, receiver, content, time)  # message between user and user
  </code></pre>
  
  <p>The relationship among <code>theUser</code>, <code>theGroup</code> and <code>Membership</code> has been explained from this <a href="https://stackoverflow.com/questions/37307783/how-to-select-the-groups-which-a-certain-user-doesnt-join-with-mysql/37307940#37307940">question</a>. Now I want to extract the conversation(<code>gpMsge</code> and <code>idMsge</code>) and display the name of corresponding sender (<code>theUser</code> and <code>theGroup</code>) in the order of the newset message in that conversation. Indeed the business logic is exactly the same with <code>Whatsapp</code>. In the first part, the sender names (individual user name if the conversation is p2p or group name if it is within group) show with the order by the time of the newest message in that conversation. And below each sender name, there are should be five newest message in that conversation. In the second part, all group with no conversation is displayed (no need to specify the order in this part).</p>
  
  <p>The difficulty for me now is the order of the conversation as the <code>gpMsge</code> and <code>idMsge</code> is isolated. How can I sort the <code>time</code> value in each table and get the name of <code>theUser</code> and <code>theGroup</code> in a table? Thank you in advance!</p>