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 1gjR3Z-0007mb-IJ for pgsql-general@arkaria.postgresql.org; Tue, 15 Jan 2019 15:55:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gjR3Y-0001p1-7w for pgsql-general@arkaria.postgresql.org; Tue, 15 Jan 2019 15:55:12 +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 1gjR3X-0001ou-7r for pgsql-general@lists.postgresql.org; Tue, 15 Jan 2019 15:55:12 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjR3P-0007rL-Mm for pgsql-general@lists.postgresql.org; Tue, 15 Jan 2019 15:55:10 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id D2EAB243F5; Tue, 15 Jan 2019 10:54:59 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 15 Jan 2019 10:54:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=y UjOiNkHvP2a+X5oWzFvNIR8Pwqg4TYt6Pk3XdHnKrY=; b=LOUNk/p93aWINOP8I YcuxXdFSDXWAiMgmnOrwxQ2Z5JXMocavv5fDPwnrwHMFlr8E62RF0nhgk3gJRSL/ ZSQV1GT5iuaJ0dkivVTrbaKfqQ5hwY9BO1DJSH23ye9btkxI+YZNZmAVXrviQZ/v ivXo4p9QL6/eAfhoEGpyYXsY299a2/zKlaEV/Mu48UZ8LcQqqCEoF/mo+dVbIIbH 1DQMSPBQ2L+f7msO4e0bxAGGOr/hFHS5F6l9tLUQvOIRijhF4Bj7kwm5+f4O48R3 d5PQTgkUa1tFae97u3hB0yWx0GbTyLGEfewWPt+YC/lURau+JPU9bnYPcVpa9tpB Z+64w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=yUjOiNkHvP2a+X5oWzFvNIR8Pwqg4TYt6Pk3XdHnK rY=; b=cCpIpo8tLWOfiqEtloxiIw5bWVKGGHfzKhBtwz0ooal3bzjZj2QRVlood 8f+FHP4qVsHTcYhBoDLkwN8smPlZnMoK8qa9vgw2El2zWaNH5NvcNiXOuUGMRq2g gA2NoAQxC27rFiXffYkhYwGAzRCVGae8l2kNF9VXd5pGT7aCsxAWkS1vafSMhF7s ma1tIo3AsVB3uC/p0qVK4ovH/iN47kWhzSebDPRUWud7CkDqqGFTmyZFgSsuxGLs D6ZRE5VWagxp7aiVS4WBGncwLi96OcWx8yONOzr2QYx6bwlVTwXxsgsHprjmP4Nx vre7obtD8Q1lLmIXHudumF0lOYBbw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrgeefgdekudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkffffg ggjggtgfesthekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegr ughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucfkphepjedurddvud dvrddufeegrdefnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghv vghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id B6E84100BB; Tue, 15 Jan 2019 10:54:58 -0500 (EST) Subject: Re: Refining query statement To: Rich Shepard , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Tue, 15 Jan 2019 07:54:57 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/15/19 7:39 AM, 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: > > select (C.contact_id, C.lname, C.fname, C.direct_phone, O.org_name, > A.next_contact) > from Contacts as C, Organizations as O, Activities as A > where C.org_id = O.org_id and C.contact_id = A.contact_id and >       A.next_contact <= 'today' and A.next_contact > '2018-12-31' and >       A.next_contact is not null; > > but would benefit from tweaking. When I have had multiple contacts with > someone I want only the most recent one displayed, not all, and they should > be no more ancient than a defined period (e.g., a month). > >   I want to learn how to make this query cleaner and more flexible. When I > write the UI for this I want to be able to specify a data range in addition > to a fixed 'today'. Pointers on what to read will be very helpful. For the above I could see using a datepicker widget that allows for multidate select. The specifics would depend on the software you are using to write the UI. > > TIA, > > Rich > > -- Adrian Klaver adrian.klaver@aklaver.com