Re: [SQL] Was: fetch first rows of grouped data

2007-08-28 Thread Sebastian Ritter
Sorry my last post isnt complete. This would have to be part of a sub select. It would be more lilke: SELECT * from cities LEFT OUTER JOIN (SELECT c.id as city_id, event.id FROM cities c LEFT OUTER JOIN events e ON (c.id = e.city_id) WHERE c.id = cities.id ORDER BY e.date DESC LIMIT 2) as x ON (c

[SQL] Was: fetch first rows of grouped data

2007-08-28 Thread Guy Fraser
Hi there I have a list of events that take place in a certain city at a certain date. Now I would like to have the first two (ordered by date) events for each city. Is there a way to do this with one query? I am using PostgreSQL 7.4.