From: Jan Kohnert <nospam001-lists@jan-kohnert.de>
To: pgsql-general@lists.postgresql.org
Subject: Re: Subquery to select max(date) value
Date: Wed, 13 Feb 2019 11:32:02 +0100
Message-ID: <36049066.FvorQsyXWJ@kohnert-n4> (raw)
In-Reply-To: <alpine.LNX.2.20.1902121414490.15295@salmo.appl-ecosys.com>
References: <alpine.LNX.2.20.1902121414490.15295@salmo.appl-ecosys.com>
Am Dienstag, 12. Februar 2019, 23:23:49 CET schrieb Rich Shepard:
> The query is to return the latest next_contact date for each person. Using
> the max() aggregate function and modeling the example of lo_temp on page 13
> of the rel. 10 manual I wrote this statement:
You don't even need a subselect to do so:
select
P.person_id, P.lname, P.fname, P.direct_phone,
O.org_name, max(A.next_contact) as next_contact
from People as P
join Organizations as O
on P.org_id = O.org_id
join Activities as A
on P.person_id = A.person_id
group by
P.person_id, P.lname, P.fname,
P.direct_phone, O.org_name;
--
Kind regards Jan
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: nospam001-lists@jan-kohnert.de
Subject: Re: Subquery to select max(date) value
In-Reply-To: <36049066.FvorQsyXWJ@kohnert-n4>
References: <alpine.LNX.2.20.1902121414490.15295@salmo.appl-ecosys.com> <36049066.FvorQsyXWJ@kohnert-n4>
* 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