Difference between revisions of "Hierarchal data management (MySQL)"

From Wiki @ Karl Jones dot com
Jump to: navigation, search
(Created page with "This article discusses hierarchal data management for MySQL. == Select full path to leaf == <pre> SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3, t4.name a...")
(No difference)

Revision as of 08:48, 19 February 2016

This article discusses hierarchal data management for MySQL.

Select full path to leaf

SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3, t4.name as lev4
FROM category AS t1
LEFT JOIN category AS t2 ON t2.parent = t1.category_id
LEFT JOIN category AS t3 ON t3.parent = t2.category_id
LEFT JOIN category AS t4 ON t4.parent = t3.category_id
WHERE t1.name = 'ELECTRONICS' AND t4.name = 'FLASH';

Source: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

See also