EDIT: After reading some of your answers i noticed i don't need recursion but some queries to work with the tree. I'm currently reading the following post http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ which is giving the basic concepts i didn't knew and the proper way to go. So thanks a lot, i'll keep on reading the posted links :)
i'm working on a tree where every node can have childs or not. Every node has its own auto generated node_id by the childs to reference its parent. A simple table example could be the following:
CREATE TABLE IF NOT EXISTS `arbres` ( `node_id` int(11) NOT NULL AUTO_INCREMENT, `pare_id` int(11) DEFAULT NULL, PRIMARY KEY (`node_id`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=470 ; ALTER TABLE arbres ADD CONSTRAINT FK_E6A4F221A4467B16 FOREIGN KEY (pare_id) REFERENCES arbres(node_id) ON DELETE CASCADE;
What i'm trying is to find a query which is able to select every child and so on, i mean the childs of the childs, the childs of the childs of the childs, etc in a single query. I'm very new to sql so i could accomplish it with multiples sql sentences which is not a good idea. Thx for your time.