Re: sql interogation - Mailing list pgsql-novice

From Tom Lane
Subject Re: sql interogation
Date
Msg-id 18153.1098713173@sss.pgh.pa.us
Whole thread Raw
In response to sql interogation  ("cristivoinicaru" <cristivoinicaru@dmhi.ct.ro>)
List pgsql-novice
"cristivoinicaru" <cristivoinicaru@dmhi.ct.ro> writes:
> I want like sql interogation to select only one record from each "gc" group
> record (who has the same code "gc" (that means that the "gc" field will be
> unique key)) with the following two condition:
> 1)from each "gc" group of records to select the record who has the value of
> "ora" field maxim.
> 2)if two ore more record have the same value of the maxim value of the "ora"
> to select oly one of them

I don't think you can do (2) very nicely in standard SQL, because the
results aren't fully defined and the SQL standard does not like poorly
defined behaviors ;-).  However there is a nonstandard extension in
Postgres that is exactly what you need: SELECT DISTINCT ON.  See the
"weather reports" example in the SELECT reference page --- your "gc"
corresponds to weather stations and "ora" to report date.

            regards, tom lane

pgsql-novice by date:

Previous
From: Steven Klassen
Date:
Subject: Re: sql interogation
Next
From: pakis5253001@yahoo.ca (PavelK)
Date:
Subject: haracter encoding problem with delphi