pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: smoshiro@hotmail.com
To: pgsql-sql@postgresql.org
Subject: Min and Max
Date: 29 Nov 2002 10:55:54 -0800
Message-ID: <18210f93.0211291055.6831ae6d@posting.google.com> (raw)

Hello, everybody!

I've trouble to make a "simple"(?) query...

The following table is an example:

table: children
id_father | child_name | child_age
----------+------------+------------
        1 | John       | 2
        1 | Joe        | 3
        1 | Mary       | 4
        1 | Cristine   | 4
        2 | Paul       | 1
        2 | Stephany   | 2
        2 | Raul       | 5

How can I get the rows of the children name and its "father" such that
they have the min child_ages? I expect the following rows as result:

id_father | child_name | child_age
----------+------------+------------
        1 | John       | 2
        2 | Paul       | 1

The same for the max child_ages...

id_father | child_name | child_age
----------+------------+------------
        1 | Mary       | 4
        1 | Cristine   | 4
        2 | Raul       | 5

I tried to use min() and max() with group by but I could not get the
expected results:

-- 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;


Any suggestions?

Thanks In Advance,
Sergio Oshiro



view thread (4+ messages)  latest in thread

Message-ID: <18210f93.0211291055.6831ae6d@posting.google.com>
Permalink:  ../18210f93.0211291055.6831ae6d@posting.google.com/
Also on:    postgresql.org/message-id/18210f93.0211291055.6831ae6d@posting.google.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: smoshiro@hotmail.com
  Subject: Re: Min and Max
  In-Reply-To: <18210f93.0211291055.6831ae6d@posting.google.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox