Re: Group By Question - Mailing list pgsql-general

From Chris Velevitch
Subject Re: Group By Question
Date
Msg-id AANLkTikk5mU450gkrc9B1e=L7DsKzuF5ze-F_E4-r6n9@mail.gmail.com
Whole thread Raw
In response to Group By Question  ("Andrew E. Tegenkamp" <andrew@g3.com>)
List 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

pgsql-general by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: querying the version of libpq
Next
From: "Greg Sabino Mullane"
Date:
Subject: Re: querying the version of libpq