pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Refining query statement
Date: Tue, 15 Jan 2019 18:45:53 +0100
Message-ID: <aa3d9ff5-608e-02d6-5a3e-4585e4491630@gmx.net> (raw)
In-Reply-To: <cf026bdf-f68e-f17f-0ab7-b7fb53a5b8bd@aklaver.com>
References: <alpine.LNX.2.20.1901150738320.5845@salmo.appl-ecosys.com>
	<9a5976c8-76da-f06d-9840-5dcf8723e38b@gmx.net>
	<26851021-69e3-36e4-170d-40ed7219a180@gmail.com>
	<cf026bdf-f68e-f17f-0ab7-b7fb53a5b8bd@aklaver.com>

Adrian Klaver schrieb am 15.01.2019 um 17:44:
>>> So we end up with something like this:
>>>
>>>      select distinct on (C.contact_id) C.contact_id, C.lname, C.fname, C.direct_phone, O.org_name, A.next_contact
>>>      from Contacts as C
>>>        join Organizations as O on C.org_id = O.org_id
>>>        join Activities as A on C.contact_id = A.contact_id
>>>      where A.next_contact <= 'today'
>>>        and A.next_contact > '2018-12-31'
>>>      order by c.contact_id, a.next_contact DESC;
>>
>> And I've never liked this method (though I'm old and crotchety)....
>>
> 
> What is the specific objection?
> 
> To me:
> 
> 1) Plus side. It saves an explicit sub-query
> 
> 2) Minus side. It is not portable. But then complete portability is a unicorn in my opinion.

I think Ron was referring to the JOIN operator, rather than the DISTINCT ON

  





view thread (32+ messages)  latest in thread

Message-ID: <aa3d9ff5-608e-02d6-5a3e-4585e4491630@gmx.net>
Permalink:  ../aa3d9ff5-608e-02d6-5a3e-4585e4491630@gmx.net/
Also on:    postgresql.org/message-id/aa3d9ff5-608e-02d6-5a3e-4585e4491630@gmx.net

 · 

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: spam_eater@gmx.net
  Subject: Re: Refining query statement
  In-Reply-To: <aa3d9ff5-608e-02d6-5a3e-4585e4491630@gmx.net>
  References: <alpine.LNX.2.20.1901150738320.5845@salmo.appl-ecosys.com> <9a5976c8-76da-f06d-9840-5dcf8723e38b@gmx.net> <26851021-69e3-36e4-170d-40ed7219a180@gmail.com> <cf026bdf-f68e-f17f-0ab7-b7fb53a5b8bd@aklaver.com> <aa3d9ff5-608e-02d6-5a3e-4585e4491630@gmx.net>

* 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