pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
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 07:46:42 -0800
Message-ID: <f92397e5-fd33-200b-96e1-79ba70ca0e16@aklaver.com> (raw)
In-Reply-To: <alpine.LNX.2.20.1902130736190.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>

On 2/13/19 7:37 AM, Rich Shepard wrote:
> On Wed, 13 Feb 2019, Adrian Klaver wrote:
> 
>> The LEFT JOIN. There are rows in people for which there no records coming
>> from the sub-select on activities, so the row is 'padded' with NULL 
>> values
>> for the missing data.
> 
> Adrian,
> 
> I assume it's the inner left join. I'll trace what's happening at each step

AFAIK there is no inner left join:
https://www.postgresql.org/docs/10/sql-select.html#SQL-FROM
"
join_type

     One of

         [ INNER ] JOIN

         LEFT [ OUTER ] JOIN

         RIGHT [ OUTER ] JOIN

         FULL [ OUTER ] JOIN

         CROSS JOIN
"

> and learn where to specify no nulls.

You can't it is the nature of the join:

"LEFT OUTER JOIN returns all rows in the qualified Cartesian product 
(i.e., all combined rows that pass its join condition), plus one copy of 
each row in the left-hand table for which there was no right-hand row 
that passed the join condition. This left-hand row is extended to the 
full width of the joined table by inserting null values for the 
right-hand columns. Note that only the JOIN clause's own condition is 
considered while deciding which rows have matches. Outer conditions are 
applied afterwards."


What you are seeing are records for which there is a person in the 
people table that either:

1) Do not have a record under that person_id in the activities table

or

2) Do not have a record that meets the date filtering you are doing on 
next_contact.

> 
> Thanks,
> 
> Rich
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (48+ messages)  latest in thread

Message-ID: <f92397e5-fd33-200b-96e1-79ba70ca0e16@aklaver.com>
Permalink:  ../f92397e5-fd33-200b-96e1-79ba70ca0e16@aklaver.com/
Also on:    postgresql.org/message-id/f92397e5-fd33-200b-96e1-79ba70ca0e16@aklaver.com

 · 

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: adrian.klaver@aklaver.com, rshepard@appl-ecosys.com
  Subject: Re: Subquery to select max(date) value
  In-Reply-To: <f92397e5-fd33-200b-96e1-79ba70ca0e16@aklaver.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> <f92397e5-fd33-200b-96e1-79ba70ca0e16@aklaver.com>

* 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