Re: query problem - Mailing list pgsql-sql

From Josh Berkus
Subject Re: query problem
Date
Msg-id 200208291345.25680.josh@agliodbs.com
Whole thread Raw
In response to query problem  (Marco Muratori <marco.muratori@emaze.net>)
List pgsql-sql
Marco,

> Is there a way to obtain this records by performing one
> single query and not by making for each city something like
> "SELECT city,date FROM table WHERE city='London' AND date>'2002-07-19
> 15:39:15+00' ORDER BY date ASC LIMIT 1;"?

Close.  Try:

SELECT city, MAX("date") as last_date
FROM table
WHERE "date" > $date
GROUP BY city
ORDER BY city

Though as an aggregate query, this will be slow on large tables.

--
-Josh BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: Marco Muratori
Date:
Subject: query problem
Next
From: Jeff Boes
Date:
Subject: Large number of lookups