Help with SQL staterment - Mailing list pgsql-novice

From Chris Campbell
Subject Help with SQL staterment
Date
Msg-id 453A24085F801842AEA8D0B6B269065DD23DCC9842@HDMC.cds.local
Whole thread Raw
Responses Re: Help with SQL staterment  (Thom Brown <thom@linux.com>)
Re: Help with SQL staterment  (Steve Crawford <scrawford@pinpointresearch.com>)
List pgsql-novice

Hello list,

 

Using PostgreSQL 9.0.2 I’m trying to write a sql statement to extract specific rows from the following data set.  I’ve looked at the documentation that talks about the Max() function but the example doesn’t go far enough:

 

The sample fields/dataset are as follows

 

PaymentKey,  ContactKey,  PaymentDate

1,  100, 01/01/2011

2,  100, 12/30/2010

3,  100, 12/31/2010

4,  101, 01/02/2011

5,  101, 12/25/2010

 

What I want returned are rows grouped by contactkey showing the corresponding payment key and payment date for the record that has the max (newest) payment date.  So I would want my result set to look like this:

 

1,  100, 01/01/2011

4,  101, 01/02/2011

 

I would be using this query as a sub query that is (left) joined to a master query by ContactKey

 

Any assistance would be greatly appreciated.

 

Thank you,

 

Chris

pgsql-novice by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: pg_advisory_locks in a multithreaded application context
Next
From: Thom Brown
Date:
Subject: Re: Help with SQL staterment