Re: Postgres-sql-php - Mailing list pgsql-sql

From Oliveiros Cristina
Subject Re: Postgres-sql-php
Date
Msg-id 005601c934fa$1c4879f0$ec5a3d0a@marktestcr.marktest.pt
Whole thread Raw
In response to Postgres-sql-php  ("Zied Kharrat" <khzied@gmail.com>)
Responses Re: Postgres-sql-php
List 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 -----
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 :)

pgsql-sql by date:

Previous
From: Aarni
Date:
Subject: Re: SELECT multiple MAX(id)s ?
Next
From: "Zied Kharrat"
Date:
Subject: Re: Postgres-sql-php