Re: Group By Question

From: Chris Velevitch <chris(dot)velevitch(at)gmail(dot)com>
To: "Andrew E(dot) Tegenkamp" <andrew(at)g3(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Group By Question
Date: 2010-10-05 16:08:55
Message-ID: AANLkTikk5mU450gkrc9B1e=L7DsKzuF5ze-F_E4-r6n9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

That's getting too complicated. It can be done simply as:

SELECT DISTINCT(test.people.id) test.people.id, test.people.name, test.likes.ref
FROM test.people LEFT JOIN test.likes ON test.people.id = test.likes.ref
ORDER BY test.people.id, test.likes.date DESCENDING

Assuming people.id is unique, the order by clause makes the first row
of every group the most recent like and distinct expression keeps only
the first row for each person.

Chris
--
Chris Velevitch
Manager - Adobe Platform Users Group, Sydney
m: 0415 469 095
www.apugs.org.au

Adobe Platform Users Group, Sydney
October 2010: Flash Builder for SalesForce
Date: 25th October, 6pm for 6:30 start
Details and RSVP coming soon

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2010-10-05 16:14:07 Re: querying the version of libpq
Previous Message Peter Geoghegan 2010-10-05 15:52:28 Re: querying the version of libpq