Re: Extract only maximum date from column

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Extract only maximum date from column
Date: 2025-12-04 20:22:31
Message-ID: 71e7ffd-2151-cf3c-b1d9-5b8d66bb9b6@appl-ecosys.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 4 Dec 2025, David G. Johnston wrote:

> I would go with a lateral join subquery of the contracts table. Using an
> aggregates to perform ranking is an anti-pattern. You want the contract
> ranked first when ordered by contract_date. Either use a window function
> to explicitly rank the contracts or use a limit/fetch clause to simply
> return the first ordered one.

David,

It's 'contacts' rather than 'contracts'; a minor typo.

I'll read on making a lateral join. Thanks.

> You also seem to have completely missed joining people to contracts -
> suggest using explicit “join” clauses to make that error less likely.

Oops! My bad. Fixed.

Regards,

Rich

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bryan Sayer 2025-12-04 20:24:40 Re: Extract only maximum date from column
Previous Message Rich Shepard 2025-12-04 20:18:14 Re: Extract only maximum date from column