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 1vRFWv-00AQWa-04 for pgsql-general@arkaria.postgresql.org; Thu, 04 Dec 2025 20:02:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRFWu-004Vtj-0N for pgsql-general@arkaria.postgresql.org; Thu, 04 Dec 2025 20:02:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vRFWt-004VtZ-2V for pgsql-general@lists.postgresql.org; Thu, 04 Dec 2025 20:02:20 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vRFWs-0039s8-0u for pgsql-general@postgresql.org; Thu, 04 Dec 2025 20:02:19 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-3ec3cdcda4eso1111117fac.1 for ; Thu, 04 Dec 2025 12:02:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764878536; x=1765483336; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=10CWh9ex/HhJp94Vz1hZYL08XIrwvvNOAX6IIC3d9OY=; b=BPNp5G9wUfQdDaQhdnbqv1u2XvC9KBkpYiCemcA+OGcf7QYs/EqhEWRysdzPhlCBGS J7cH5Rq9CxyxohamQ4Ze0mrbc7w9YHI4jtBpnzlNi6iSPEzPw92nNVyacNUXLC33Yf2g QCUAsi43elvtjE/udeg7XLbc26Rp8fPfNwOs8kIir1OH5O1DqF8ajWlmoLUNNwAlbHrh 4lKhop35Q1mqlozXXhhd0r93FO3X7lQOW2676E23PX4CWboPYmO44fNX5Q6nXs7FxUoK k4vyBjzAaDjWoOjUuwhtG+ufb7arwfDmIo9gOR9aBJq/VN3uMwwdT0cDUDBBcck+0f/7 dqdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764878536; x=1765483336; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=10CWh9ex/HhJp94Vz1hZYL08XIrwvvNOAX6IIC3d9OY=; b=A3VpnNLWn77UYxuYkzeokfXseAwywMP+R/6YOtFsBzhh6iW+BRl8wVQPRARDqmQVcx +CkCZNLENlPH/xitNS8RcVcu/fPHEK7oVLV+J9bjIGBrbbjO7t0btQ0xq+vLmYGcLQNq YyUM73zpDbmrrfBAYluveoyxOFEF4y9PTtnCP/zTdcA3u1f2HmJVhsJj70lqWy7bps/n TMb4Xp0UcBBD2sGfoE4GKbkMakj8RLmUo95yda2/PNCrn3DM2q5rJJyKIXAalDJoVMh2 KM3h1ESq36uuVtvHSPdVkM5IIkxQ6p+RHncXHEsMB/CSKdmfGsIe4T/zBKY6mvIklpPE b1yQ== X-Gm-Message-State: AOJu0YxIaLmZwdHJj+Ns30XzwicXninwi7+LHPTLpeKQRQjgPY05iRxx J+u+wPLEZfWGyakM3+xt4VFWBj/9GPWJ8MBVptXSa52L6T6oBR9HNl6FQqY1J8gys/7Dq5TS1eg FRbHnALAN9vuLAc/Ze74HpPdXNMsvsM+zMQ== X-Gm-Gg: ASbGncupgNhjvLu0EtfHAW8AOfv4+8LOqp7UhnSdUKzz6vxmxbZK5FKfaLM4QId0psa Ajw/tRT9WhwWh0ybEyY3io6biHU7g9bVJUehV/m1EhFK58kbIiZrb2AkjsafO/ACNqQhDc7O1mn 4JL4pdJnfZODjg9POvOYpn1ADL3ky2Jcn1X1DRJJXpCOvOMGmdzjqhitD77LI3d8cNm65jk8CgH h3piMbKIUABS8KfwN06cFBgbtJIE0UA9brcnuX4Eed3NUY2Qh16r2aqLkx8OXIX1bwyuqcr X-Google-Smtp-Source: AGHT+IHgtpWpBUjTqxhemofxrKt9Rce/1yY36JFonnM24MVQapUBYdq+WvQoFF/riUc9MDRkb9Z9CiFAJtno4zYf/oM= X-Received: by 2002:a05:6808:2899:b0:453:7cb1:871d with SMTP id 5614622812f47-4537cb191d6mr1542379b6e.52.1764878535671; Thu, 04 Dec 2025 12:02:15 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Thu, 4 Dec 2025 15:02:04 -0500 X-Gm-Features: AQt7F2qNgRKNHay3Kjmtk9d6audd7N1E4qRiMEO7F3A18N3YTtLSES43k511AmI Message-ID: Subject: Re: Extract only maximum date from column To: pgsql-general Content-Type: multipart/alternative; boundary="00000000000030c736064525ceef" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000030c736064525ceef Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Dec 4, 2025 at 2:55=E2=80=AFPM Rich Shepard wrote: > 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 >=3D '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? > May not be the only way, but it's how I do it: SELECT * FROM foo WHERE some_dt =3D (SELECT MAX(some_dt) FROM foo); It might return more than one row... --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --00000000000030c736064525ceef Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Dec 4, 2025 at 2:55=E2=80=AFPM Ri= ch Shepard <rshepard@appl-ec= osys.com> wrote:
I want the script to e= xtract 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 >=3D '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?

M= ay not be the only way, but it's how I do it:
SELECT *=C2=A0
FROM foo=
WHERE some_dt =3D (SELECT MAX(so= me_dt) FROM foo);

It might return more than= one row...

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'= m still alive.
<Redacted> lobster!
--00000000000030c736064525ceef--