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 1vRFQ0-00AOxo-2R for pgsql-general@arkaria.postgresql.org; Thu, 04 Dec 2025 19:55:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRFPz-004Q90-2Z for pgsql-general@arkaria.postgresql.org; Thu, 04 Dec 2025 19:55:12 +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 1vRFPz-004Q8r-1U for pgsql-general@lists.postgresql.org; Thu, 04 Dec 2025 19:55:11 +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 1vRFPx-0039oG-13 for pgsql-general@postgresql.org; Thu, 04 Dec 2025 19:55:10 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 2F2862A14D6 for ; Thu, 4 Dec 2025 11:55:08 -0800 (PST) Date: Thu, 4 Dec 2025 11:55:08 -0800 (PST) From: Rich Shepard Reply-To: Rich Shepard To: pgsql-general@postgresql.org Subject: Extract only maximum date from column Message-ID: MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I want the script to extract only the maximum `next_contact' date and haven't learned how to do this from my reading of web sites. The script: select p.person_nbr, p.company_nbr, c.next_contact from people as p, contacts as c where c.next_contact >= '2025-11-01' group by p.person_nbr, p.company_nbr, c.next_contact order by p.person_nbr, p.company_nbr, max(c.next_contact); returns all contacts rather than only the latest one. Is using a sub-select the proper way? TIA, Rich