How to find all participants of a chat thread?
The problem with that though is that for my application I need to order this result set by post date, so the author should always be on top, and UNION ALL messes up the order.


Actually, the order should be preserved as UNION ALL is implemented to just append rows. (Might be revealing to include the offending query in your question.)
Also, you might merge tables post and post_replyinto a single table. Depends.

And if you typically have many rows per user in a chat, use a recursive CTE to get the distinct count of users with best performance using a matching index:


Fast way to count distinct column values (using an index?)