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 1gkWVR-0006rS-FZ for pgsql-general@arkaria.postgresql.org; Fri, 18 Jan 2019 15:56:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gkWVQ-0004nY-1H for pgsql-general@arkaria.postgresql.org; Fri, 18 Jan 2019 15:56:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gkWVP-0004nR-M0 for pgsql-general@lists.postgresql.org; Fri, 18 Jan 2019 15:56:27 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gkWVM-0000qz-Ut for pgsql-general@lists.postgresql.org; Fri, 18 Jan 2019 15:56:26 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 9F8BE99353 for ; Fri, 18 Jan 2019 07:56:22 -0800 (PST) Date: Fri, 18 Jan 2019 07:56:22 -0800 (PST) From: Rich Shepard Reply-To: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Re: Refining query statement [DONE] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 15 Jan 2019, Rich Shepard wrote: > Working with my sales/client management system using psql I have a select > statement to identify contacts to be made. This statement works: With much patient advice from Adrian, David, Thomas, and Ron I fixed the schema and the query statement. To close this thread I post the query that meets my goal and provide the information I need. Formatting this as a report will be the job of SQLAlchemy and wxPython. /* This query selects all contact information and notes from those people whose next_contact date is today or earlier; only active persons. */ /* Specify columns */ SELECT p.lname, p.fname, p.direct_phone, p.active, o.org_name, a.act_date, a.act_type, a.notes, a.next_contact, a.comment /* Specify tables. */ FROM People AS p JOIN Organizations AS o ON o.org_id = p.org_id JOIN Activities AS a ON a.person_id = p.person_id /* Specify rows */ WHERE p.active = TRUE AND a.next_contact <= 'today'::date GROUP BY o.org_name, p.person_id, a.person_id, a.act_date, a.act_type, a.next_contact ORDER BY p.person_id, a.next_contact DESC; I really appreciate your help. Best regards, Rich