title: Select from two tables and order by datetime stamps
body: <p>I have two MySQL tables similar to below:</p>
  
  <pre><code>MESSAGES_IN
  messageID
  receivedDate
  message
  
  MESSAGES_OUT
  messageID
  sentDate
  message
  </code></pre>
  
  <p>Basically, I want to select messages from both tables and order them by their respective dates.  For example, if the data set were:</p>
  
  <pre><code>MESSAGES_IN
  1  2014-04-24 12:26:33  Test message inbound
  2  2014-04-24 19:12:15  Another test message inbound
  
  MESSAGES_OUT
  1  2014-04-24 12:31:33  Test message outbound
  2  2014-04-24 19:16:15  Another test message outbound
  </code></pre>
  
  <p>Then I want the output to be:</p>
  
  <pre><code>2014-04-24 12:26:33  Test message inbound
  2014-04-24 12:31:33  Test message outbound
  2014-04-24 19:12:15  Another test message inbound    
  2014-04-24 19:16:15  Another test message outbound
  </code></pre>
  
  <p>I've attempted the query below but I'm getting error that my ORDER BY is an unknown column:</p>
  
  <pre><code>SELECT i.receivedDate, i.message
  FROM MESSAGES_IN i
  UNION
  SELECT sentDate, o.message
  FROM MESSAGES_OUT o
  ORDER BY receivedDate, sentDate;
  </code></pre>
  
  <p>Thank you!</p>