Are you having a problem with orphaned posts in the database? Do you know how that happened?
You can run a similar query to associate posts with different threads.
Code:
UPDATE xf_post
SET thread_id = 4
WHERE thread_id = 2
Replace the id numbers as before, except this time it's the thread_id and not the node_id.
Then you will need to run this:
Admin CP -> Tools -> Rebuild Caches -> Rebuild Thread Information