I have a comments table. Every single comment could be a response to another comment.
Table structure:
CREATE TABLE comments
(
id integer NOT NULL,
content text,
root integer NULL,
date_added timestamp without time zone DEFAULT now()
)
I need to select the newest 10 threads with their responses, so in result I may have for example 10 threads and 8 responses. I'm not sure hot to do that. I've tried:
SELECT content FROM comments
ORDER BY date_added DESC
LIMIT 10 + (SELECT COUNT(*) FROM COMMENTS WHERE root IS NOT NULL)
But this has no proper effect.