Help with GROUP_CONCAT & GROUP_BY
Posted: Thu Nov 08, 2007 11:44 pm
I was trying something with one of the functions that mysql provided - Group_Concat to get some data in an order that would make it easy for me to analyze... I wasn't particularly clear about getting the data in a format that I wanted... Using group_concat do you know of a way of getting the sub children too in a single line? As of now, I am able to get the following:
Parent -> A
Children -> B E F G
Parent -> B
Children-> C D
From a Table:
A | B
A | E
A | F
A | G
B | C
B | D
Where X | Y indicates that X is related to Y somehow.
What I wanted was something like if C and D are children of B, then I want something like:
Parent -> A
Children -> B{C,D} E F G
The statement that I framed was:
SELECT ip2 AS Parent, GROUP_CONCAT(ip1 SEPARATOR ', ') AS Children FROM br GROUP BY ip2;
With great difficulty I was able to write a solution but I realised it isn't doing what I want it to do... Someone please help me...
Parent -> A
Children -> B E F G
Parent -> B
Children-> C D
From a Table:
A | B
A | E
A | F
A | G
B | C
B | D
Where X | Y indicates that X is related to Y somehow.
What I wanted was something like if C and D are children of B, then I want something like:
Parent -> A
Children -> B{C,D} E F G
The statement that I framed was:
SELECT ip2 AS Parent, GROUP_CONCAT(ip1 SEPARATOR ', ') AS Children FROM br GROUP BY ip2;
With great difficulty I was able to write a solution but I realised it isn't doing what I want it to do... Someone please help me...