MySQL Forums
Forum List  »  Newbie

GROUP_CONCAT question
Posted by: ben jaz
Date: August 17, 2014 02:14AM

Hi.

I want to see a list of all parent links (that have parent field NULL) and a grouped list of their children. I am building a small 2 layer navigation.

My query doesn't seem to show correct results. I appreciate any help.

So far this is what my query returns:http://grab.by/zwQq

Cheers



CREATE TABLE `admin_nav` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT '',
`parent` int(11) DEFAULT NULL,
`link` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1




SELECT admin_nav.title,
admin_nav.id,
children.children,
children.parent
FROM admin_nav
LEFT OUTER JOIN (SELECT Group_concat(title) AS children,
parent
FROM admin_nav
WHERE parent IS NOT NULL
GROUP BY id) AS children
ON children.parent = admin_nav.id
WHERE admin_nav.parent IS NULL
ORDER BY admin_nav.title

Options: ReplyQuote


Subject
Written By
Posted
GROUP_CONCAT question
August 17, 2014 02:14AM
August 17, 2014 12:29PM
August 18, 2014 01:26AM
August 18, 2014 01:31AM
August 18, 2014 09:11AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.