I'm using mySQL on phpMyAdmin, my table is
| code | name | parent | |------|------|--------| | 10 |node10| 5 | | 5 |node05| 2 |
where 5 is the parent of 10 (which is also a node), I need to select for a specific node A all childs and subchilds until the last leaf, I tried to do that but I've got also 2 levels of subchilds (for example for node 2 I've got 5 and 10)
SELECT *
FROM `composant`
WHERE parent IN(
SELECT code
FROM `composant`
WHERE parent=2 OR code=2
)
so how can we get loop to get all the subnodes ?
RECURSIVE Common-Table-Expressions
. AFAIK, MariaDB offers CTEs, but MySQL 5.7 does not. Check How to do the Recursive SELECT query in MySQL?