Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace

From: Chris Bitmead <chris(at)bitmead(dot)com>
To: pgsql-hackers(at)postgreSQL(dot)org
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace
Date: 2000-01-25 03:09:50
Message-ID: 388D13FE.4E75CA05@bitmead.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-sql
Philip Warner wrote:
> >I don't feel overly strongly about this, but if I remember right you can
> >do some pretty cool things with this feature, provided you do define
> >some semantics clearly. Like I think you can find the first tuple
> >(given some ORDER BY clause) that fulfills some criteria. I think it is
> >
> >SELECT DISTINCT ON name name, age ORDER BY age;
> >
> >will get the youngest person. This might not be clearly specified now,
> >but
> >as long as it's useful, how about clearly defining it? I don't know that
> >there is an easy way of doing this in standard SQL.
> 
> I don't know about PGSQL, but in other systems, I use:
> 
>     Select <whatever> from <wherever> order by age asc limit to 1 row;
> 
> I *think* the PGSQL syntax is:
> 
>     Select <whatever> from <wherever> order by age asc limit 1;

I think what I really meant was...

SELECT DISTINCT ON firstname firstname, age ORDER BY age.

Which would find the youngest person called "fred", the youngest person
called "paul", the youngest person called "jim" etc etc. which your
limit example wouldn't do.

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2000-01-25 03:18:29
Subject: Re: [HACKERS] Happy column dropping
Previous:From: Bruce MomjianDate: 2000-01-25 03:09:42
Subject: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace

pgsql-sql by date

Next:From: Tom LaneDate: 2000-01-25 03:45:49
Subject: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace
Previous:From: Bruce MomjianDate: 2000-01-25 03:09:42
Subject: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group