title: How to retrieve a chat msg with sender and receiver username in mysql
body: <pre><code>chat Table
  -------------------------------------------------------
  msg_id  msg(description of msg)   sender(id)   receiver(id)
  -------------------------------------------------------
  1       hello                      2             1
  1       how are you                1             2
  ----------------------------------------------------------
  
  user table
  -----------------------
  u_id   username
  -----------------------
  1       usman
  2       Ali
  ---------------------
  </code></pre>
  
  <p>here you see two tables one is for chat and one table is for user
  i make a relationship between these two table but i feel difficulty how to extract data from these table.</p>
  
  <p><strong>what i want..</strong>  </p>
  
  <p>i want to extract each sender msg with its username and each reciver name with its username like facebook chat so i make this query</p>
  
  <p>i put this query in database </p>
  
  <pre><code>select u.user_name UserName,msg.msg
  from user u,messages msg 
  where (msg.sender or msg.receiver)=(select u_id from user where u_id= 1 )
      and msg.sender=1
  order by msg.msg_id desc
  </code></pre>
  
  <p>but this query repeat sender message with receive name and receiver msg with sender name</p>
  
  <p>i want to show sender and reciver msg show separably with their name tell me any method how i fix it.</p>