Re: query problem

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Marco Muratori <marco(dot)muratori(at)emaze(dot)net>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: query problem
Date: 2002-08-29 20:45:25
Message-ID: 200208291345.25680.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2002-08-30 03:18:58 Re: [SQL] LIMIT 1 FOR UPDATE or FOR UPDATE LIMIT 1?
Previous Message Zenith Vivas 2002-08-29 19:20:46 How to Select with more than one AND in a Where SQL Clause?