Re: Selecting table row with latest date [RESOLVED]

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Selecting table row with latest date [RESOLVED]
Date: 2021-08-19 19:34:05
Message-ID: alpine.LNX.2.20.2108191226250.15165@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 19 Aug 2021, David G. Johnston wrote:

> Yeah, you wrote two from clauses…

David,

Mea culpa! I did. Got that fixed.

Now, this query:
-------
Select distinct on (p.person_nbr) p.person_nbr,
c.contact_date, max(c.next_contact) as next_contac from contacts,
people as p, contacts as c
where c.next_contact <= current_date and
p.person_nbr = c.person_nbr
group by p.person_nbr, c.contact_date
order by p.person_nbr, c.contact_date desc;
-------
results in usable information; e.g.,
person_nbr | contact_date | next_contact
------------+--------------+-------------
1 | 2021-07-21 | 2021-07-26
4 | 2021-07-28 | 2021-08-16
6 | 2021-07-28 | 2021-08-16
9 | 2019-03-26 | 2020-11-17
11 | 2018-04-05 | 2020-11-17
13 | 2021-07-28 | 2021-08-16

My thanks to all of you,

Rich

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-08-19 21:49:38 Re: Selecting table row with latest date [RESOLVED]
Previous Message Adrian Klaver 2021-08-19 19:00:17 Re: Selecting table row with latest date