Re: How can I group all children by their parent ? - Mailing list pgsql-general

From Pujol Mathieu
Subject Re: How can I group all children by their parent ?
Date
Msg-id 53C7CCB8.8090702@realfusio.com
Whole thread Raw
In response to How can I group all children by their parent ?  (Arup Rakshit <aruprakshit@rocketmail.com>)
List pgsql-general

Le 17/07/2014 15:08, Arup Rakshit a écrit :
How can I group all children by their parent ? 

id email parent_id
1 test@test.com nil
2 test1@test.com 1
3 email 1
4 email 2
5 email nil
6 email 3
 
Regards,
Arup Rakshit
Did you mean
SELECT array_agg(id), array_agg(email), parent_id FROM ... GROUP BY parent_id
id email parent_id
[1,5] [test@test.com,email] nil [2,3] [test1@test.com,email] 1
[4] [email] 2
[6] [email] 3

or
SELECT id, email, parentid FROM ... ORDER BY parent_id
id email parent_id
1 test@test.com nil
5 email nil
2 test1@test.com 1
3 email 1
4 email 2
6 email 3
Regards
Mathieu Pujol

pgsql-general by date:

Previous
From: François Beausoleil
Date:
Subject: Re: How can I group all children by their parent ?
Next
From: Arup Rakshit
Date:
Subject: Re: How can I group all children by their parent ?