with recursive as (
SELECT par.Id,
par.Name,
par.ParentID,
par.IsDeleted
FROM table1 par
JOIN table1 chi
ON par.Id = chi.ParentId
union all
SELECT par.Id,
par.Name,
par.ParentID,
rec.IsDeleted
FROM table1 par
JOIN recursive rec
ON rec.Id = par.ParentId
),
check_tbl as (
select Id,
sum(IsDeleted) as IsDeleted
from recursive
group by Id
having sum(IsDeleted)=0
)
select table1.id, Name, ParentID, table1.IsDeleted
from check_tbl join table1 on table1.Id=check_tbl.Id
;