Help with GROUP_CONCAT & GROUP_BY

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Help with GROUP_CONCAT & GROUP_BY

Post 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...
Last edited by legend986 on Fri Nov 09, 2007 1:25 am, edited 2 times in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Descriptive Subjects

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

In this case I think you'll essentially need two queries.

Your other option is to use Modified Preorder Tree Traversal
Post Reply