title: Private Message Database Design
body: <p>Alright, so I think I'm pretty close to having what I need, but I'm unsure about a couple of things:</p>
  
  <pre><code>TABLE messages
  
  message_id
  message_type
  sender_id
  timestamp
  
  TABLE message_type
  
  message_type_code (1, 2, 3)
  name (global, company, personal)
  
  TABLE message_to_user
  
  message_id
  receiver_id
  status (read/unread)
  </code></pre>
  
  <p>Goals:</p>
  
  <ol>
  <li>Be able to send GLOBAL messages to all users.</li>
  <li>Send PERSONAL messages between 1 or more users.</li>
  <li>Determine if any of these messages have been read or not by the the receiver.</li>
  </ol>
  
  <p>Questions:</p>
  
  <ol>
  <li>Does my schema take care of all that it needs to?</li>
  <li>What would a sample SQL query look like to populate someones inbox, bringing in GLOBAL messages as well as PERSONAL messages - I'd like to be able to determine which is which for the UI.</li>
  </ol>
  
  <p>And please feel free to add to my schema if you feel it would benefit.</p>