title: For threaded messaging, not sure how to generate unique thread_id ONLY WHEN a thread_id is not specified
body: <p>I expect that this is a rather common problem seeing as a lot of sites use threaded messaging, but I haven't been able to find anything on the internets.  </p>
  
  <p>Basically the way I envision this working is I have a column called thread_id in my messages table.  The column is not unique, because obviously a lot of messages will be sharing the same thread.  What I'd like to see happen is when I insert a new message, if I specify a thread_id, it uses it as expected, but if I don't, it uses the next available thread_id by auto incrementing the highest value.</p>
  
  <p>So if I have a series of messages with thread ids: 1,1,2,2,3,2,2,3,3,4,2,5,3,3,3,4 and then I insert a row without an id, it would use the id 6.</p>
  
  <p>Is this possible?  If not, how do most people accomplish threaded messaging?</p>
  
  <p>Thanks!</p>