From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Refining query statement |
Date: | 2019-01-15 17:45:53 |
Message-ID: | aa3d9ff5-608e-02d6-5a3e-4585e4491630@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2019-01-15 18:31:40 | Re: Refining query statement |
Previous Message | Rich Shepard | 2019-01-15 17:17:08 | Re: Refining query statement |