← hierarchy-data-closure-table
change table alias
+14 −14 · 1 file changed
-
mysql/p_get_tree.sql+14 −14
@@ -9,26 +9,26 @@ CREATE PROCEDURE `p_get_tree`( ) COMMENT 'Query all descendants nodes by a node id, return as a result set' BEGIN SELECT - d.`id`, - d.`is_deleted`, - d.`parent_id`, + node.`id`, + node.`is_deleted`, + node.`parent_id`, CONCAT( - REPEAT('-', p.`path_length`), - d.`name` - ) AS tree, - p.`path_length`, + REPEAT('-', path.`path_length`), + node.`name` + ) AS name, + path.`path_length`, GROUP_CONCAT( crumbs.`ancestor_id` SEPARATOR ',' ) AS breadcrumbs FROM - `prefix_nodes` AS d - JOIN `prefix_nodes_paths` AS p - ON d.`id` = p.`descendant_id` + `prefix_nodes` AS node + JOIN `prefix_nodes_paths` AS path + ON node.`id` = path.`descendant_id` JOIN `prefix_nodes_paths` AS crumbs - ON crumbs.`descendant_id` = p.`descendant_id` - WHERE p.`ancestor_id` = `node_id` - AND d.`is_deleted` = 0 - GROUP BY d.`id` + ON crumbs.`descendant_id` = path.`descendant_id` + WHERE path.`ancestor_id` = `node_id` + AND node.`is_deleted` = 0 + GROUP BY node.`id` ORDER BY breadcrumbs ; END$$