Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d6ZIZ-0001e9-Oa for pgsql-sql@arkaria.postgresql.org; Fri, 05 May 2017 09:13:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d6ZIZ-00030v-BF for pgsql-sql@arkaria.postgresql.org; Fri, 05 May 2017 09:13:15 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d6ZIX-0002ya-I8 for pgsql-sql@postgresql.org; Fri, 05 May 2017 09:13:13 +0000 Received: from hub.ringways.co.uk ([88.211.105.30] helo=ringways.co.uk) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d6ZIU-0005qu-Rv for pgsql-sql@postgresql.org; Fri, 05 May 2017 09:13:12 +0000 Received: from eddie.ringways.co.uk ([10.1.1.115]) by ringways.co.uk with esmtp (Exim 4.89) (envelope-from ) id 1d6ZIR-000MfG-CQ for pgsql-sql@postgresql.org; Fri, 05 May 2017 10:13:08 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: Re: Most recent row Date: Fri, 5 May 2017 10:13:07 +0100 User-Agent: KMail/1.9.10 References: <201705050925.04194.gary.stainburn@ringways.co.uk> <20170505083220.wxdqm3bpwfo2dgre@hermes.hilbert.loc> In-Reply-To: <20170505083220.wxdqm3bpwfo2dgre@hermes.hilbert.loc> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201705051013.07196.gary.stainburn@ringways.co.uk> X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 112280 [May 05 2017] X-KLMS-AntiSpam-Version: 5.7.0.14 X-KLMS-AntiSpam-Envelope-From: gary.stainburn@ringways.co.uk X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Info: LuaCore: 219 219 5c25d3d119ea48db9a5032001f8be732dc5ace77, {msgid_created_by_recepient}, 127.0.0.200:5.2.1;eddie.ringways.co.uk:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;127.0.0.199:5.2.1,7.1.2;ringways.co.uk:7.1.1 X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, 2017/05/04 14:05:37 X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.721, bases: 2017/05/05 02:49:00 #9492834 X-KLMS-AntiVirus-Status: Clean, skipped X-Spam-Score: -50.8 (--------------------------------------------------) X-Spam-Report: Spam detection software, running on the system "ollie2.ringways.co.uk", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see Gary Stainburn for details. Content preview: On Friday 05 May 2017 09:32:21 Karsten Hilbert wrote: > On Fri, May 05, 2017 at 09:25:04AM +0100, Gary Stainburn wrote: > > This question has been asked a few times, and Google returns a few > > different answers, but I am interested people's opinions and suggestions > > for the *best* wat to retrieve the most recent row from a table. > > > > My case is: > > > > create table people ( > > p_id serial primary key, > > ...... > > ); > > > > create table assessments ( > > p_id int4 not null references people(p_id), > > as_timestamp timestamp not null, > > ...... > > ); > > > > select p.*, (most recent) a.* > > from people p, assessments a > > .. > > ; > > You will need to provide a definition for *exactly* what > "most recent" means in this context. > > Karsten [...] Content analysis details: (-50.8 points, 15.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -50 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.1 SCORE_RCPTS Adding score for each recipient -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 1.0 RING_SAFE No description available. X-forward-disable: yes X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On Friday 05 May 2017 09:32:21 Karsten Hilbert wrote: > On Fri, May 05, 2017 at 09:25:04AM +0100, Gary Stainburn wrote: > > This question has been asked a few times, and Google returns a few > > different answers, but I am interested people's opinions and suggestions > > for the *best* wat to retrieve the most recent row from a table. > > > > My case is: > > > > create table people ( > > p_id serial primary key, > > ...... > > ); > > > > create table assessments ( > > p_id int4 not null references people(p_id), > > as_timestamp timestamp not null, > > ...... > > ); > > > > select p.*, (most recent) a.* > > from people p, assessments a > > .. > > ; > > You will need to provide a definition for *exactly* what > "most recent" means in this context. > > Karsten Appologies all. I though that was obvious, but it is only obvious for me. What I mean by most recent is the assessment record with the highest (most recent) timestamp. Specfically join a people row with the assessment row for that people. Each assessment will assign scores for the person being assessed. The scores from their most recent assessment are their current scores and what I want to appear in the view. In the live project it will actually be a left outer join in case the person has not yet been assessed. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql