Re: query problem - Mailing list pgsql-sql

From Jean-Luc Lachance
Subject Re: query problem
Date
Msg-id 3D6FCF6D.8E072AE0@nsd.ca
Whole thread Raw
In response to query problem  (Marco Muratori <marco.muratori@emaze.net>)
List pgsql-sql
I think you meant min(date)...


Josh Berkus wrote:
> 
> 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
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


pgsql-sql by date:

Previous
From: Jean-Luc Lachance
Date:
Subject: Re: query problem
Next
From: GB Clark
Date:
Subject: Re: Retrieving the new "nextval" for primary keys....