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 1gtgmQ-0005H5-Jp for pgsql-general@arkaria.postgresql.org; Tue, 12 Feb 2019 22:43:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtgmO-0006tS-Ve for pgsql-general@arkaria.postgresql.org; Tue, 12 Feb 2019 22:43:52 +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 1gtgmO-0006tL-Lw for pgsql-general@lists.postgresql.org; Tue, 12 Feb 2019 22:43:52 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtgmM-00085S-PU for pgsql-general@lists.postgresql.org; Tue, 12 Feb 2019 22:43:52 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 8D4E899356 for ; Tue, 12 Feb 2019 14:43:48 -0800 (PST) Date: Tue, 12 Feb 2019 14:43:48 -0800 (PST) From: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Re: Subquery to select max(date) value In-Reply-To: <2780074d-3b87-b154-8bc6-a0f898fbdde2@openvistas.net> Message-ID: References: <2780074d-3b87-b154-8bc6-a0f898fbdde2@openvistas.net> User-Agent: Alpine 2.20 (LNX 67 2015-01-07) 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: Precedence: bulk On Tue, 12 Feb 2019, Jeff Ross wrote: > Try (select (max(A.next_contact) from A) Thanks, Jeff. The syntax accepted by psql is A.next_contact = (select (max(A.next_contact)) from Activities as A) but the date is not included in the output. The revised statement is now: select (P.person_id, P.lname, P.fname, P.direct_phone, O.org_name, A.next_contact) from People as P, Organizations as O, Activities as A where P.org_id = O.org_id and P.person_id = A.person_id and A.next_contact = (select (max(A.next_contact)) from Activities as A) group by A.next_contact, O.org_id, P.person_id; This produces the first 5 colums in the outer select but no next_contact date. When I move A.next_contact to the head of the select list each row begins with 'infinity'. I'm still missing the requisite knowledge. Rich