Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjSmo-0006BC-Jb for pgsql-general@arkaria.postgresql.org; Tue, 15 Jan 2019 17:46:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gjSmn-00086l-E1 for pgsql-general@arkaria.postgresql.org; Tue, 15 Jan 2019 17:46:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjSmn-00086e-5x for pgsql-general@lists.postgresql.org; Tue, 15 Jan 2019 17:46:01 +0000 Received: from mail-out.m-online.net ([212.18.0.9]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjSml-00027i-9I for pgsql-general@lists.postgresql.org; Tue, 15 Jan 2019 17:46:00 +0000 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43fHnK3qxRz1qvwZ for ; Tue, 15 Jan 2019 18:45:57 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43fHnK1Dllz1qqkb for ; Tue, 15 Jan 2019 18:45:57 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id rH6a9aHaOEcP for ; Tue, 15 Jan 2019 18:45:56 +0100 (CET) Received: from [192.168.178.37] (ppp-93-104-67-29.dynamic.mnet-online.de [93.104.67.29]) by mail.mnet-online.de (Postfix) with ESMTP for ; Tue, 15 Jan 2019 18:45:53 +0100 (CET) Subject: Re: Refining query statement To: pgsql-general@lists.postgresql.org References: <9a5976c8-76da-f06d-9840-5dcf8723e38b@gmx.net> <26851021-69e3-36e4-170d-40ed7219a180@gmail.com> From: Thomas Kellerer Message-ID: Date: Tue, 15 Jan 2019 18:45:53 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver schrieb am 15.01.2019 um 17:44: >>> So we end up with something like this: >>> >>>      select distinct on (C.contact_id) C.contact_id, C.lname, C.fname, C.direct_phone, O.org_name, A.next_contact >>>      from Contacts as C >>>        join Organizations as O on C.org_id = O.org_id >>>        join Activities as A on C.contact_id = A.contact_id >>>      where A.next_contact <= 'today' >>>        and A.next_contact > '2018-12-31' >>>      order by c.contact_id, a.next_contact DESC; >> >> And I've never liked this method (though I'm old and crotchety).... >> > > What is the specific objection? > > To me: > > 1) Plus side. It saves an explicit sub-query > > 2) Minus side. It is not portable. But then complete portability is a unicorn in my opinion. I think Ron was referring to the JOIN operator, rather than the DISTINCT ON