select * from tbwhere parent_id not in(select t1.idfrom tb t1 join tb t2 on t1.id = t2.parent_id)
select * from a t1where not exists( select 1 from a t2 where t2.id=t1.parent_id)