Storing the first thread id is not that easy since it is currently not available when the message is written. The only id that is available is the message id that has been replied to.
Sure it might be possible to read this message and check if a "thread id" has been set and duplicate this id for the new message but this requires another SQL query I try to avoid.
Mhh-I've think about it... If you change the available id from "message id that has been replied to" to "thread id", which is included then in every post, then you don't have more or more compicated queries... :whistle:
In this case just don't save and read the "message id to replied of", just save in every message the thread id (=the first message id) and sort all messages to date...