pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brent Wood <Brent.Wood@niwa.co.nz>
To: Rich Shepard <rshepard@appl-ecosys.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Subquery to select max(date) value
Date: Wed, 13 Feb 2019 23:51:31 +0000
Message-ID: <1550101890489.14429@niwa.co.nz> (raw)
In-Reply-To: <alpine.LNX.2.20.1902131509560.10544@salmo.appl-ecosys.com>
References: <alpine.LNX.2.20.1902121414490.15295@salmo.appl-ecosys.com>
	<2780074d-3b87-b154-8bc6-a0f898fbdde2@openvistas.net>
	<alpine.LNX.2.20.1902121443290.15295@salmo.appl-ecosys.com>
	<alpine.LNX.2.20.1902121446460.15295@salmo.appl-ecosys.com>
	<CAD3a31U1_V0z9X22wD=1FQ9iYr+KbY8J3NxQpk0Q5Dq5M151fw@mail.gmail.com>
	<alpine.LNX.2.20.1902121513500.15295@salmo.appl-ecosys.com>
	<CAD3a31VPA6FTLWyQ5KGVXF6ac0y=VG9UaJLEdvyBZWCefrSisw@mail.gmail.com>
	<alpine.LNX.2.20.1902130623150.10544@salmo.appl-ecosys.com>
	<fcc4bce0-6e59-d9eb-3644-548b993b84fd@aklaver.com>
	<alpine.LNX.2.20.1902130736190.10544@salmo.appl-ecosys.com>
	<7c015580-fe20-be68-076c-ded42d8bf1f1@aklaver.com>
	<875ztno1l6.fsf@news-spur.riddles.org.uk>
	<alpine.LNX.2.20.1902131411590.10544@salmo.appl-ecosys.com>
	<0dee994f-120d-06b6-4aea-a10060d2687c@aklaver.com>
	<alpine.LNX.2.20.1902131509560.10544@salmo.appl-ecosys.com>

I have not really followed this thread but would not a query along the lines of

select * from activity where person_id = n and timestamp = (select max(timestamp) from activity where person_id = n);

give the required answer ie, always return the latest result for the specified person_id??


Brent Wood

Programme leader: Environmental Information Delivery
NIWA
DDI:  +64 (4) 3860529



[cid:imagee69a07.PNG@f4290eba.45ae534e]<http://www.niwa.co.nz;


Brent Wood
Principal Technician - GIS and Spatial Data Management
Programme Leader - Environmental Information Delivery
T +64-4-386-0529

National Institute of Water & Atmospheric Research Ltd (NIWA)
301 Evans Bay Parade, Greta Point, Wellington
Connect with NIWA: niwa.co.nz<https://www.niwa.co.nz; Facebook<https://www.facebook.com/nzniwa; Twitter<https://twitter.com/niwa_nz; LinkedIn<https://www.linkedin.com/company/niwa; Instagram<https://www.instagram.com/niwa_science;

To ensure compliance with legal requirements and to maintain cyber security standards, NIWA's IT systems are subject to ongoing monitoring, activity logging and auditing. This monitoring and auditing service may be provided by third parties. Such third parties can access information transmitted to, processed by and stored on NIWA's IT systems.


________________________________________
From: Rich Shepard <rshepard@appl-ecosys.com>
Sent: Thursday, February 14, 2019 12:13
To: pgsql-generallists.postgresql.org
Subject: Re: Subquery to select max(date) value

On Wed, 13 Feb 2019, Adrian Klaver wrote:

> Given a sufficiently large date range that may not be true as you may have
> contacted a given person multiple times during that range and generated
> multiple activities records.

Adrian,

This is true as it has occurred. I want only the most recent activity row
associated with that person_id. (NB: while I'm really comfortable with DDL
statements my DML experience is seriously lacking and that's what I need to
improve now.)

I've just read a couple of blog posts on the LATERAL join added in 9.3 and
understand it in theory. Properly applying it to my application is now my
focus (and I need to re-read Andrew's example very closely.)

Best regards,

Rich

Attachments:

imagee69a07.PNG (image/png, 12.0K) download view image

view thread (48+ messages)  latest in thread

Message-ID: <1550101890489.14429@niwa.co.nz>
Permalink:  ../1550101890489.14429@niwa.co.nz/
Also on:    postgresql.org/message-id/1550101890489.14429@niwa.co.nz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: Brent.Wood@niwa.co.nz, rshepard@appl-ecosys.com
  Subject: Re: Subquery to select max(date) value
  In-Reply-To: <1550101890489.14429@niwa.co.nz>
  References: <alpine.LNX.2.20.1902121414490.15295@salmo.appl-ecosys.com> <2780074d-3b87-b154-8bc6-a0f898fbdde2@openvistas.net> <alpine.LNX.2.20.1902121443290.15295@salmo.appl-ecosys.com> <alpine.LNX.2.20.1902121446460.15295@salmo.appl-ecosys.com> <CAD3a31U1_V0z9X22wD=1FQ9iYr+KbY8J3NxQpk0Q5Dq5M151fw@mail.gmail.com> <alpine.LNX.2.20.1902121513500.15295@salmo.appl-ecosys.com> <CAD3a31VPA6FTLWyQ5KGVXF6ac0y=VG9UaJLEdvyBZWCefrSisw@mail.gmail.com> <alpine.LNX.2.20.1902130623150.10544@salmo.appl-ecosys.com> <fcc4bce0-6e59-d9eb-3644-548b993b84fd@aklaver.com> <alpine.LNX.2.20.1902130736190.10544@salmo.appl-ecosys.com> <7c015580-fe20-be68-076c-ded42d8bf1f1@aklaver.com> <875ztno1l6.fsf@news-spur.riddles.org.uk> <alpine.LNX.2.20.1902131411590.10544@salmo.appl-ecosys.com> <0dee994f-120d-06b6-4aea-a10060d2687c@aklaver.com> <alpine.LNX.2.20.1902131509560.10544@salmo.appl-ecosys.com> <1550101890489.14429@niwa.co.nz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox