1   select  id, name, parentid  from table where parentid='0' 
     2       select id,name parentid from table where parentid=id  (from 1)