Re: Refining query statement

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Ron <ronljohnsonjr(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Refining query statement
Date: 2019-01-15 16:44:43
Message-ID: cf026bdf-f68e-f17f-0ab7-b7fb53a5b8bd@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/15/19 8:02 AM, Ron wrote:

>> the best way to do it:
>>
>> 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.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2019-01-15 16:46:32 Re: aggregate functions are not allowed in UPDATE
Previous Message Alexander Farber 2019-01-15 16:42:24 aggregate functions are not allowed in UPDATE