title: Mysql Join A table with with two other tables based on a flag column
body: <p>I have a table which contains messages from both users and organizations. The table contains a field called <code>usertype</code> which indicates whether the message was sent by a user or an organization. </p>
  
  <p>I have to join this table with two tables containing user details and organization details respectively.</p>
  
  <p>How can i write a join query with thes 2 tables?</p>
  
  <p>I think i can achieve this via a union, but can it be done using only joins?</p>
  
  <p>Table - USER fetch : user name<br>
  Table - Organization fetch : organization name<br>
  Table Messages - entries userid , usertype.
  have to get username by checking datatype</p>