Subject: Extract only maximum date from column

From: Thiemo Kellner <[email-masked]>
Date: Fri, 5 Dec 2025 13:16:20 +0100

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

---

From: Rich Shepard <[email-masked]>
Date: Fri, 5 Dec 2025 08:04:40 -0800 (PST)

> Am I missing something?

Thiemo,

Nope. I was the one missing something:

select p.person_nbr, p.company_nbr, max(c.next_contact)
from people as p
inner join contacts as c
       on p.person_nbr = c.person_nbr
where c.next_contact >= '2025-11-01'
group by p.person_nbr, p.company_nbr
order by p.person_nbr, p.company_nbr;

and,

  person_nbr | company_nbr |    max 
------------+-------------+------------
         226 |         736 | 2025-12-02
         367 |         396 | 2026-01-06
         464 |        2286 | 2025-11-05
         465 |         702 | 2025-11-17
         537 |         356 | 2025-11-03
         553 |         367 | 2025-12-02
         554 |         641 | 2025-12-02
...

Mea culpa!

Many thanks,

Rich

---

From: Thiemo Kellner <[email-masked]>
Date: Sat, 6 Dec 2025 09:07:52 +0100 (GMT+01:00)

Glad, to have been of assistance :-)