I have the following command:
SELECT *
FROM Posts P
WHERE P.ThreadId = 0
ORDER BY
(SELECT MAX(R.Time)
FROM Posts R
WHERE R.ThreadId = P.Id) DESC
This selects all threads and orders them by the time of their last reply. Threads without a reply are always behind threads with replies and in random order. I want this command to also order threads without replies by their creation time intermingled with the other threads.
How can I achieve this? (Side note: Threads and Replies are using the same table "Post". A thread has the ThreadId 0 while a reply has the ThreadId of a parent post.)