From: | Paul Linehan <linehanp(at)tcd(dot)ie> |
---|---|
To: | Ken Benson <Ken(at)infowerks(dot)com> |
Cc: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Help with a JOIN. |
Date: | 2014-07-20 17:08:11 |
Message-ID: | CAF4RT5R8Dv5aeteME9Mff5cSAcm43BqJznS6RnLJFU=H7YC4hw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Funny how reading one's own email is helpful! :-)
The answer of course is
SELECT t.ticket_id, t.ticket_description, x.c_com_id, z.comments_comment
FROM
(
SELECT ticket_id, MAX(c.comment_id) AS c_com_id
FROM comment c
WHERE c.comments_timestamp < UNIX_TIMESTAMP(NOW() - INTERVAL 2 YEAR)
GROUP BY ticket_id
)
AS x INNER JOIN ticket AS t ON t.ticket_id = x.ticket_id
INNER JOIN comment AS z ON z.comment_id = x.c_com_id;
i.e. using the comment_id as the discriminator - which I actually
*_wrote_*, but was
unable to apply until I'd reread my own email. Funny thing the mind (well,
mine anyway! :-) ).
Thanks to the list and esp. Ken.
Rgs,
Paul...
--
linehanp(at)tcd(dot)ie
Mob: 00 353 86 864 5772
From | Date | Subject | |
---|---|---|---|
Next Message | Shreesha | 2014-07-20 19:28:27 | Creating a hot copy of PostgreSQL database |
Previous Message | Paul Linehan | 2014-07-20 16:51:25 | Re: Help with a JOIN. |