Sample database (Categories in a Nested Set Model):
CREATE TABLE `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`lft` int(11) NOT NULL,
`rgt` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
INSERT INTO category(name, lft, rgt) values("Primary", 0, 1000);
INSERT INTO category(name, lft, rgt) values("Secondary", 1, 500);
INSERT INTO category(name, lft, rgt) values("Tertiary", 2, 20);
INSERT INTO category(name, lft, rgt) values("Tertiary2", 21, 30);
I want to obtain all the parents of the bottom child categories (probably concat?) like this:
Primary > Secondary > Tertiary
Primary > Secondary > Tertiary2
Besides playing with BETWEEN lft AND rgt and CONCAT, i'm pretty stuck and could use some tips and information about getting the required results. Thanks!