Preve all! There is a table
CREATE TABLE `hers` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8_unicode_ci', `parent_id` INT(11) NULL DEFAULT NULL, PRIMARY KEY (`id`) ) COLLATE='utf8_unicode_ci' ENGINE=InnoDB AUTO_INCREMENT=0 ;
In which there is infa:
id name parent_id 1 her1 NULL 2 her2 1 3 her3 1 4 her4 2 5 her5 4 6 her6 3
Question: How can I build a tree in one query without creating tables, view, etc? For example, how to find the root parent for id = 5? And how, for example, for him to find a non-indigenous, but second (after the indigenous) descendant? So that the result looks like this:
id 1 2 4 5