Re: Selecting table row with latest date - Mailing list pgsql-general

From Rob Sargent
Subject Re: Selecting table row with latest date
Date
Msg-id 446C1708-2523-4A9F-B5EC-221BFF2D851E@gmail.com
Whole thread Raw
In response to Re: Selecting table row with latest date  (Rich Shepard <rshepard@appl-ecosys.com>)
Responses Re: Selecting table row with latest date  (Rich Shepard <rshepard@appl-ecosys.com>)
List pgsql-general


On Aug 19, 2021, at 10:06 AM, Rich Shepard <rshepard@appl-ecosys.com> wrote:

On Thu, 19 Aug 2021, Adrian Klaver wrote:

Alright now I am confused. You keep referring to contact_date, yet the
query is referring to next_contact. Are they the same thing, different
things or other?

Adrian,

The table has 5 columns: person_nbr, contact_date, contact_type, notes, and
next_contact.

I want the query to find all person_nbr whose most recent contact_date has a
next_contact date <= today. I don't need prior contact_dates and their
next_contact dates because some go back several years. I want to know those
I need to contact again based on our most recent contact.

HTH,

Did you try David J’s suggestion? or maybe
select person_nbr, max(next_contact) group by person_nbr where next_contact < now();

A table with person_nbr (pk), next_contact would make this much easier.  Seems to me a person can only have one next-contact? (as opposed to all future_contact)

Rich



pgsql-general by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: PostgreSQL Automatic Failover Windows Server
Next
From: "David G. Johnston"
Date:
Subject: Re: string_agg distinct order by