How to get super parent from table with self relationship
Something like this

/*
create table #table1 (id int, parentId int)

INSERT INTO #table1
VALUES (1,null),
(2,1)
,(3,2)
,(4,3)
,(5,4)
,(10, null)
,(11,10)
,(8,11)
*/
declare @child int; 
set @child=4;
with prt as
(select 1 rn,id, parentid from #table1 where id=@child
union all
select rn+1 rn, t.id,t.parentid from #table1 t join prt on prt.parentid=t.id
where t.parentid is not null
)
select top 1 parentid from prt order by rn desc


Recursive CTE