Last active
September 5, 2021 05:22
-
-
Save raihan-uddin/9ab4541fee35e4b236e55cd1c3395228 to your computer and use it in GitHub Desktop.
Managing Hierarchical Data in MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ | |
//SELECT t1.title, t1.id, t1.root FROM chart_of_ac AS t1 LEFT JOIN chart_of_ac as t2 ON t1.id = t2.root WHERE t2.id IS NULL AND t1.title like '%cash%' | |
select leaf node of a parant | |
//SELECT TRIM(RIGHT(TRIM(concat_ws(' ', ifnull(t1.id,''), ifnull(t2.id,''), ifnull(t3.id,''), ifnull(t4.id,'') )),20)) as id FROM chart_of_ac AS t1 LEFT JOIN chart_of_ac AS t2 ON t2.root = t1.id LEFT JOIN chart_of_ac AS t3 ON t3.root = t2.id LEFT JOIN chart_of_ac AS t4 ON t4.root = t3.id WHERE t1.id = '3' ORDER BY t1.title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment