Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F3229476AD3 for ; Mon, 2 Dec 2002 15:05:59 -0500 (EST) Received: from beamish.nsd.ca (unknown [205.150.156.194]) by postgresql.org (Postfix) with ESMTP id 62D8F476A0C for ; Mon, 2 Dec 2002 14:54:31 -0500 (EST) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id OAA04350; Mon, 2 Dec 2002 14:54:18 -0500 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma004346; Mon, 2 Dec 02 14:54:05 -0500 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id OAA18136; Mon, 2 Dec 2002 14:52:47 -0500 Message-ID: <3DEBBA62.CFFE0F34@nsd.ca> Date: Mon, 02 Dec 2002 14:54:10 -0500 From: Jean-Luc Lachance X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.9-31 i686) X-Accept-Language: en MIME-Version: 1.0 To: Dennis =?iso-8859-1?Q?Bj=F6rklund?= Cc: Sergio Oshiro , pgsql-sql@postgresql.org Subject: Re: Min and Max References: Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by reddog.nsd.ca id OAA18136 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/16 X-Sequence-Number: 10604 If you do not mind non standard, how about: SELECT DISTINCT ON(id_father) * FROM children ORDER BY id_father, child_age; Dennis Bj=F6rklund wrote: >=20 > On 29 Nov 2002, Sergio Oshiro wrote: >=20 > > How can I get the rows of the children name and its "father" such that > > they have the min child_ages? > > > > -- the following does not return the child_name... > > select id_father, min(child_age) from children group by id_father; > > select id_father, max(child_age) from children group by id_father; >=20 > You could join one of the above with the table itself and get the result. > Something like >=20 > select * > from ( select id_father, min(child_age) > from children > group by id_father) as r, > children > where children.id_father =3D r.id_father > and children.min =3D r.min; >=20 > -- > /Dennis >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org