Le 17/07/2014 15:08, Arup Rakshit a écrit :
How can I group all children by their parent ?
id email parent_id
1 t...@test.com nil
2 te...@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] [t...@test.com,email] nil [2,3] [te...@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 t...@test.com nil
5 email nil
2 te...@test.com 1
3 email 1
4 email 2
6 email 3
Regards
Mathieu Pujol