title: Merging and sorting two tables
body: <p>I have two tables.</p>
  
  <p>"threads" with the columns ID, forumID, title, content, unixtime</p>
  
  <p>"comments" with the columns ID, threadID, content, unixtime</p>
  
  <p>I would like to do a mysql query which sorts all the rows within these two tables based on their unixtime, but also not showing the same "threadID" twice.</p>
  
  <p>The following query will merge the two tables and sort them, but I cant remove duplicates of the threads. I've tried with some GROUP BY and DISTINCT, but with no luck.</p>
  
  <pre><code>(SELECT unixtime, ID, threadID FROM comments)
  UNION
  (SELECT unixtime, ID, forumID FROM threads)
  ORDER BY unixtime DESC
  </code></pre>
  
  <p>Its for showing of the frontpage of a forum, therefor it would make no sense to let the same thread appear more than once.</p>
  
  <p>EDIT: I want to show both the newest comments and the newest threads.</p>