Difference between revisions of "Hierarchal data management (MySQL)"
From Wiki @ Karl Jones dot com
Karl Jones (Talk | contribs) (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...") |
Karl Jones (Talk | contribs) (→See also) |
||
Line 18: | Line 18: | ||
* [[Database]] | * [[Database]] | ||
* [[MySQL]] | * [[MySQL]] | ||
+ | |||
+ | [[Category:Computing]] | ||
+ | [[Category:Databases]] | ||
+ | [[Category:MySQL]] |
Latest revision as of 03:35, 25 April 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/