Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mGl57-0008Jk-Mu for pgsql-general@arkaria.postgresql.org; Thu, 19 Aug 2021 16:39:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mGl55-0004Io-DJ for pgsql-general@arkaria.postgresql.org; Thu, 19 Aug 2021 16:39:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mGl55-0004Ig-30 for pgsql-general@lists.postgresql.org; Thu, 19 Aug 2021 16:39:51 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mGl52-0003Jv-Ol for pgsql-general@lists.postgresql.org; Thu, 19 Aug 2021 16:39:50 +0000 Received: by mail-pf1-x42b.google.com with SMTP id j187so6002406pfg.4 for ; Thu, 19 Aug 2021 09:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=vTheEaemMqbKvRs5diLbL8ADJGcJ6R7PYesGkJx4wzI=; b=PbN56os+xbvBLPX32Ce/puDUBeU57S2ZVu1Ca03dFVYoA5QJA7uk2cYsK4flI7OwFh +B18awe9GkxsxPDXpeJzhP+EdcdG6e9UDJP26O+sttuCAM+7CODqbY83Tu4ftNsbFRtm FvH+A57NEpMsnJDkOdMlfjIQkHGxMGRHK4z+ZSB0wHXkkPBuAOT0m/Ejb5cGVy8ZXp4T kYOoBPYMWYOFo/6Jh/zHaYmH0VOCyerSpEUxs6D6itto2U55D/NOWiWr5tDpoCJym8wR rgiCA2EFvFr1AFoUvs/AtbxUWPje5oFUwcuDmTheopL8oqnnRvAySXVMhTNsptxiayp5 L8AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=vTheEaemMqbKvRs5diLbL8ADJGcJ6R7PYesGkJx4wzI=; b=UFChXyLnAGBqaIwqYxCSg5+oDi7toAT/MmV6XeQrldq4HZndyLljUyvAUK/5+us4FA onpcogNhoYUeM1OSfOq3EVA546CnkNDW62C4VTE7qFSBD7g+Kuqc5vEGGWKSPL9xd2eZ CmG0tfCz9m89jvyGozpStt6Nb2ZbvyoM3JnaU5X4R7JW9EG++DnJaUfCl2UE9DetEW/m YIH69UwB7iQAurSn0OStO9WeztmIg+BRrb72gTzqjjYCgSGwvNP0rpkwlZTWxuBDDlDc A2/LtPuHBek3tvXXGoJ0BSqn6qRPCNbIkcRZwvRUZy2fpKGHBqtbebNjMfU6CFu4amNQ YN9Q== X-Gm-Message-State: AOAM533ak7AWC1aZDKP5l+cAybk87umoZ+iZukWR8U6CKlo9rsmuWUNp 25LFHDIUSLz2gnwHSLjs4ig= X-Google-Smtp-Source: ABdhPJzpGGgQTnV0XvUQspTWh96zBMaXJmpSJxYL8ONLYM1mqXh+EstYcjdc6nWEY8dnhWRGjE8fYQ== X-Received: by 2002:a63:790b:: with SMTP id u11mr14626714pgc.71.1629391186313; Thu, 19 Aug 2021 09:39:46 -0700 (PDT) Received: from smtpclient.apple ([2601:681:5500:dde0:3d89:3115:eeed:bd07]) by smtp.gmail.com with ESMTPSA id f23sm3964962pfd.61.2021.08.19.09.39.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Aug 2021 09:39:45 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Selecting table row with latest date From: Rob Sargent In-Reply-To: Date: Thu, 19 Aug 2021 10:39:44 -0600 Cc: pgsql-general Content-Transfer-Encoding: quoted-printable Message-Id: References: <1704154.1629384082@sss.pgh.pa.us> <446C1708-2523-4A9F-B5EC-221BFF2D851E@gmail.com> To: Rich Shepard X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Aug 19, 2021, at 10:31 AM, Rich Shepard = wrote: >=20 > On Thu, 19 Aug 2021, Rob Sargent wrote: >=20 >> Did you try David J=E2=80=99s suggestion? or maybe >=20 > Rob, >=20 > Yes. >=20 >> select person_nbr, max(next_contact) group by person_nbr where >> next_contact < now(); >=20 >> A table with person_nbr (pk), next_contact would make this much = easier. >> Seems to me a person can only have one next-contact? (as opposed to = all >> future_contact) >=20 > The peoples table has person_nbr as the PK. The contacts table has = multiple > rows for all contacts with that person_nbr. The contacts table has a > multicolum PK: person_nbr and contact_date as there is only one = contact on > any given day for that person. >=20 > HTH, >=20 > Rich >=20 Yeah, but my quibble is the the table you described up-thread. Your = contact table contains next_contact? I think that column should be = normalized out.=20 Using David=E2=80=99s trick as a CTE should be descent starting point = for you ultimate result? >=20 >=20