Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vRFqV-00ATiu-2L for pgsql-general@arkaria.postgresql.org; Thu, 04 Dec 2025 20:22:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRFqU-004jdD-1y for pgsql-general@arkaria.postgresql.org; Thu, 04 Dec 2025 20:22:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vRFqU-004jd4-0r for pgsql-general@lists.postgresql.org; Thu, 04 Dec 2025 20:22:34 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vRFqS-003A0a-0L for pgsql-general@postgresql.org; Thu, 04 Dec 2025 20:22:33 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id B59B82A14D6 for ; Thu, 4 Dec 2025 12:22:31 -0800 (PST) Date: Thu, 4 Dec 2025 12:22:31 -0800 (PST) From: Rich Shepard To: "pgsql-general@postgresql.org" Subject: Re: Extract only maximum date from column In-Reply-To: Message-ID: <71e7ffd-2151-cf3c-b1d9-5b8d66bb9b6@appl-ecosys.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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