Its my table:
CREATE TABLE IF NOT EXISTS `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL,
`parentid` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`))
Where parentid
Refrenced to this table.
I have this data:
Id | Name | parentid
1 Cumputer 0
2 MotherBoard 1
3 Cpu 2
4 Cpu cooling Fan 3
5 Monitor 1
Now, I want to select Cpu cooling fan
's Id and it's all parents:
1
2
3
Something like this:
SELECT a.id, b.id as list FROM `category` a INNER JOIN category b ON a.id=b.parentid
But it doesn't work.