create table paths (id int primary key auto_increment, path varchar(255));
insert into paths(path) values ('/'),('/a/'),('/a/b/'),('/a/b/c/'),('/a/b/c/d');
select * from paths;
-- select childs of /a/b/
select *
from paths
where path like ('/a/b/%');
-- select parents of /a/b/
select *
from paths
where '/a/b/' like concat(path,'%');