From: etur <rute.solipa@gmail.com>
To: pgsql-sql@postgresql.org
Subject: select the last post
Date: Tue, 19 Apr 2005 09:50:40 +0100
Message-ID: <9febecb505041901502f116211@mail.gmail.com> (raw)
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;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: rute.solipa@gmail.com
Subject: Re: select the last post
In-Reply-To: <9febecb505041901502f116211@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox