title: MySQL Query Two Tables and Max Timestamp
body: <p>I have two tables that look something like this:</p>
  
  <p>TABLE_conversations:</p>
  
  <pre><code>+-----------------+----------+----------------+------------+---------------------+--------+
  | CONVERSATION_ID | QUEUE_ID | CONTACT_NUMBER | CONTACT_ID | DATE_CREATED        | STATUS |
  +-----------------+----------+----------------+------------+---------------------+--------+
  |               1 |        1 | 15551112222    |    9000001 | 2014-09-12 00:28:24 | ACTIVE |
  |               2 |        1 | 15553334444    |    9000002 | 2014-09-12 00:32:08 | ACTIVE |
  +-----------------+----------+----------------+------------+---------------------+--------+
  </code></pre>
  
  <p>TABLE_messages:</p>
  
  <pre><code>+------------+-----------------+-------------+-------------+-----------+---------+---------------------+--------+-----------------------------------------------------------------------------------------------------------------+--------+
  | MESSAGE_ID | CONVERSATION_ID | FROM_NUMBER | TO_NUMBER   | DIRECTION | SENDER  | TIMESTAMP          | VIEWED | MESSAGE                                                                                                         | STATUS |
  +------------+-----------------+-------------+-------------+-----------+---------+---------------------+--------+-----------------------------------------------------------------------------------------------------------------+--------+
  |          1 |               1 | 15551112222 | 17021112222 | IN        | 9000001 | 2014-09-12 00:30:11 |      1 | Hello!  Is this working?                                                                     | ACTIVE |
  |          2 |               1 | 17021112222 | 15551112222 | OUT       | 8000001 | 2014-09-12 00:31:05 |      1 | Good evening!  Of course!  | ACTIVE |
  |          3 |               1 | 15551112222 | 17021112222 | IN        | 9000001 | 2014-09-12 00:31:27 |      1 | Perfect.  Thank you!                                                                                            | ACTIVE |
  |          4 |               1 | 17021112222 | 15553334444 | OUT       | 8000002 | 2014-09-12 00:32:52 |      1 | Ticket 11251 is ready for pickup.                                                                         | ACTIVE |
  +------------+-----------------+-------------+-------------+-----------+---------+---------------------+--------+-----------------------------------------------------------------------------------------------------------------+--------+
  </code></pre>
  
  <p>I'm trying to run a query to select the CONVERSATION_ID, CONTACT_NUMBER, CONTACT_ID and most recent TIMESTAMP and grouping by phone number:</p>
  
  <pre><code>SELECT TABLE_conversations.CONVERSATION_ID, TABLE_conversations.CONTACT_NUMBER,
         TABLE_conversations.CONTACT_ID, MAX(TABLE_messages.TIMESTAMP) 
  FROM TABLE_conversations, TABLE_messages 
  WHERE TABLE_conversations.STATUS='ACTIVE' 
  AND TABLE_messages.STATUS='ACTIVE' 
  GROUP BY CONTACT_NUMBER 
  ORDER BY TABLE_messages.TIMESTAMP;
  </code></pre>
  
  <p>The output I'm getting is below:</p>
  
  <pre><code>+-----------------+----------------+------------+-------------------------------+
  | CONVERSATION_ID | CONTACT_NUMBER | CONTACT_ID | MAX(TABLE_messages.TIMESTAMP) |
  +-----------------+----------------+------------+-------------------------------+
  |               1 | 15551112222    |    9000001 | 2014-09-12 00:32:52           |
  |               2 | 15553334444    |    9000002 | 2014-09-12 00:32:52           |
  +-----------------+----------------+------------+-------------------------------+
  </code></pre>
  
  <p>I'm getting the same TIMESTAMP for both.  The result I want is 2014-09-12 00:31:27 for 15551112222 and 2014-09-12 00:32:52 for 15553334444.</p>
  
  <p>Really appreciate any help!</p>