| From: | Jean-Luc Lachance <jllachan(at)nsd(dot)ca> | 
|---|---|
| To: | Dennis Björklund <db(at)zigo(dot)dhs(dot)org> | 
| Cc: | Sergio Oshiro <smoshiro(at)hotmail(dot)com>, pgsql-sql(at)postgresql(dot)org | 
| Subject: | Re: Min and Max | 
| Date: | 2002-12-02 19:54:10 | 
| Message-ID: | 3DEBBA62.CFFE0F34@nsd.ca | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-sql | 
If you do not mind non standard, how about:
SELECT DISTINCT ON(id_father) * FROM children ORDER BY id_father,
child_age;
Dennis Björklund wrote:
> 
> On 29 Nov 2002, Sergio Oshiro wrote:
> 
> > 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;
> 
> You could join one of the above with the table itself and get the result.
> Something like
> 
> select *
>   from (  select id_father, min(child_age)
>             from children
>         group by id_father) as r,
>         children
>  where children.id_father = r.id_father
>    and children.min = r.min;
> 
> --
> /Dennis
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Stephan Szabo | 2002-12-02 21:27:36 | Re: [SQL] CURRENT_TIMSTAMP | 
| Previous Message | Joel Burton | 2002-12-02 19:23:21 | Re: Combining queries while preserving order in SQL - Help! |