Re: Extract only maximum date from column
Rich Shepard <rshepard@appl-ecosys.com>
From: Rich Shepard <rshepard@appl-ecosys.com>
To: "pgsql-general@postgresql.org" <pgsql-general@postgresql.org>
Date: 2025-12-04T20:22:31Z
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