Re: How can I group all children by their parent ?

From: Pujol Mathieu <mathieu(dot)pujol(at)realfusio(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How can I group all children by their parent ?
Date: 2014-07-17 13:16:40
Message-ID: 53C7CCB8.8090702@realfusio.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)test(dot)com nil
> 2 test1(at)test(dot)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(at)test(dot)com,email] nil [2,3] [test1(at)test(dot)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(at)test(dot)com nil

5 email nil

2 test1(at)test(dot)com 1
3 email 1
4 email 2
6 email 3

Regards
Mathieu Pujol

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Arup Rakshit 2014-07-17 13:28:14 Re: How can I group all children by their parent ?
Previous Message François Beausoleil 2014-07-17 13:15:26 Re: How can I group all children by their parent ?