Recursive CTE - Tree Path
Recursive CTE - Tree Path is a SQL statement in the CTE (WITH) category. Recursive CTE can build full tree paths by concatenating parent and child names. The syntax is WITH RECURSIVE tree AS (...) SELECT *, CONCAT(path, '->', name) AS full_path FROM tree;. It returns hierarchical path. A typical example: WITH RECURSIVE category_tree AS ( SELECT id, name, parent_id, name AS path, 1 AS level FROM categories WHERE parent_id IS NULL UNION ALL SELECT c.id, c.name, c.parent_id, CONCAT(ct.path, ' > ', c.name), ct.level + 1 FROM categories c JOIN category_tree ct ON c.parent_id = ct.id ) SELECT * FROM category_tree ORDER BY path; -- Generates breadcrumb paths like: Electronics > Computers > Laptops A close relative is WITH (CTE), which common Table Expression — define a named temporary result set that can be referenced in the main query. A close relative is Recursive CTE, which a CTE that references itself, allowing hierarchical or recursive queries (org charts, tree structures).