Re: Postgres-sql-php

From: "Oliveiros Cristina" <oliveiros(dot)cristina(at)marktest(dot)pt>
To: "Zied Kharrat" <khzied(at)gmail(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Postgres-sql-php
Date: 2008-10-23 10:28:37
Message-ID: 005601c934fa$1c4879f0$ec5a3d0a@marktestcr.marktest.pt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Howdy, Zied.

The query below outputs the results as you want, but
I suspect you have a more general situation you want to solve.
If you have more than one father, say "manuel", you would want something like this ?

num father child age
1 joe bruce 14
lei 10
mike 5
2 manuel child1 35
child2 33
child3 30

Confirm, please .
Also, do you want the output ordered by age? always?

If so , tell me and we can tweak a little the query to best-fit your needs

Best,
Oliveiros

SELECT a.num,a.father,b.child,b.age
FROM
(
SELECT num,father, MAX(age)as maximo
FROM t1
GROUP BY num,father) a
RIGHT JOIN t1 b
ON b.age = a.maximo

----- Original Message -----
From: Zied Kharrat
To: pgsql-sql(at)postgresql(dot)org
Sent: Thursday, October 23, 2008 9:14 AM
Subject: [SQL] Postgres-sql-php

Hi Everybody..

Let's present my problem:

I have a table named t1 and i will insert differents values like this :

insert into t1 (num,father,child,age) values ('1','joe','bruce','14',);
insert into t1 (num,father,child,age) values ('1','joe','lei','10',);
insert into t1 (num,father,child,age) values ('1','joe','mike','5',);

when i use select * from t1 i obtain:

num father child age
1 joe bruce 14
1 joe lei 10
1 joe mike 5

i want to have

num father child age
1 joe bruce 14
lei 10
mike 5

what can i do as select request to obtain this capture?

Thanks :)

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Zied Kharrat 2008-10-23 12:46:43 Re: Postgres-sql-php
Previous Message Aarni 2008-10-23 10:00:01 Re: SELECT multiple MAX(id)s ?