From: | etur <rute(dot)solipa(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | select the last post |
Date: | 2005-04-19 08:50:40 |
Message-ID: | 9febecb505041901502f116211@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
hi there,
hi have a table called forum, and i've got this query:
this query select the messages and the number of replies to the
message individualy.
i'm trying to select the last post of each set of replies, like we see
in the foruns.
does anyone can help me
best regards,
etur
SELECT id, subject, to_char(post_time, 'YYYY.MM.DD @
HH24:MI:SS'::text) AS post_time,
content, login, messages.parent_id, replies.answered
FROM ( SELECT f.id, f.subject, f.post_time, f.content, u.login, f.parent_id
FROM forum f, system_users u
WHERE f.parent_id IS NULL AND f.user_id = u.id) messages
LEFT JOIN ( SELECT forum.parent_id, count(forum.id) AS answered
FROM forum
GROUP BY forum.parent_id) replies
ON messages.id = replies.parent_id;
From | Date | Subject | |
---|---|---|---|
Next Message | Muhammad Nadeem Ashraf | 2005-04-19 09:48:46 | Query about SQL in PostgreSQL |
Previous Message | PFC | 2005-04-19 07:44:01 | Re: Getting the output of a function used in a where clause |