Re: query problem

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: josh(at)agliodbs(dot)com
Cc: Marco Muratori <marco(dot)muratori(at)emaze(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: query problem
Date: 2002-08-30 20:02:53
Message-ID: 3D6FCF6D.8E072AE0@nsd.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)org

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message GB Clark 2002-09-02 19:50:33 Re: [SQL] Retrieving the new "nextval" for primary keys....
Previous Message Jean-Luc Lachance 2002-08-30 20:00:58 Re: query problem