Extract only maximum date from column

From: Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Extract only maximum date from column
Date: 2025-12-05 12:16:20
Message-ID: 1ad757c9-09d2-46fe-b3e0-2e09c85745dd@gelassene-pferde.biz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

Am I missing something?

select p.person_nbr
,p.company_nbr
,max(c.next_contact) -- the lasted contact in the group
from people as p
inner join contacts as c
on p.contact_id = c.id -- assumed join condition
where c.next_contact >= '2025-11-01'
group by p.person_nbr -- the group for which the latest contact is wanted
,p.company_nbr
order by p.person_nbr
,p.company_nbr;

Kind regards

Thiemo

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2025-12-05 13:41:44 Re: Extract only maximum date from column
Previous Message Marcos Pegoraro 2025-12-05 12:03:31 Frosen logical replication