title: MySQL Query: Getting the most recent forum post
body: <p>I'm doing some work for a department that has a pretty basic table structure set up for their forums in a MySQL database:</p>
  
  <p>Each post belongs to a thread and each thread belongs to a category.  There is also a users table for author information.</p>
  
  <pre><code>TABLE category:
  id (int)
  name (varchar)
  
  TABLE thread:
  id (int)
  category_id (int)
  user_id ((int)
  title (varchar)
  last_post (int) -- logs a unix timestamp of the last posts insertion
  
  TABLE post:
  id (int)
  user_id (int)
  thread_id (int)
  post (longtext)
  timestamp (int)
  
  TABLE users:
  id (int)
  username (varchar)
  </code></pre>
  
  <p>I'm trying to create a page that will display all threads a user has posted a message in (only once, so if the user has posted int the thread 3 times it should still show up only once in the list) and the most recent post added to each of those threads.  </p>
  
  <p>So these are the fields I'm trying to SELECT:<br>
  Category Name<br>
  Category Id<br>
  Thread Title<br>
  Thread ID<br>
  The message id of the most recently added message to that thread<br>
  The message text of the most recently added message to that thread<br>
  The author's user id of the most recently added message to that thread<br>
  The author's username of the most recently added message to that thread<br>
  The time the most recently added message was posted  </p>
  
  <p>It could be ordered by thread's most recent activity.</p>
  
  <p>Is this possible in one query?  Obviously a way to simplify this would be to query all threads a user has posted a message in and then send a separate query for each one to get the most recently added post info..</p>
  
  <p>Thanks!</p>