Re: Help with SQL staterment

From: Chris Campbell <ccampbell(at)cascadeds(dot)com>
To: Thom Brown <thom(at)linux(dot)com>, Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Help with SQL staterment
Date: 2011-07-01 01:41:15
Message-ID: 453A24085F801842AEA8D0B6B269065DD23DCC9846@HDMC.cds.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

> On 06/30/2011 04:04 PM, Thom Brown wrote:
>>
>> SELECT DISTINCT ON (contactkey)
>>     paymentkey, contactkey, paymentdate
>> FROM
>>     my_table
>> ORDER BY
>>     contactkey, paymentdate DESC
>
> Gives the same result as my example but your solution is much cleaner.

I would have never thought that "SELECT DISTINCT ON" would return that result set, but amazingly it works like a charm. Obviously I need to study up on that syntax.

Many thanks for all the assistance.

Chris

In response to

Responses

  • problem at 2011-07-01 12:55:46 from Phillip B Childs

Browse pgsql-novice by date

  From Date Subject
Next Message Phillip B Childs 2011-07-01 12:55:46 problem
Previous Message Tom Lane 2011-07-01 00:12:16 Re: change data type 'money' to '€'