Page 1 of 1

Help with GROUP_CONCAT & GROUP_BY

Posted: Thu Nov 08, 2007 11:44 pm
by legend986
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...

Descriptive Subjects

Posted: Fri Nov 09, 2007 1:21 am
by s.dot
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.

Posted: Fri Nov 09, 2007 1:49 am
by Kieran Huggins
In this case I think you'll essentially need two queries.

Your other option is to use Modified Preorder Tree Traversal