Hello everyone,
I am trying to find Root parent id of all children from a table in Azure Synapse using Spark/Python/SQL. Unfortunately, RECURSIVE CTE is not supported. Can anyone help me how to use SQL on a parent-child tree structure without CTE. Here is my sample data:
declare @project table (Projid int
, parent_t_id int
, taskid varchar(2)
, Name varchar
)
insert into @project
select 1, 0, 'T1', 'A' union
select 2, 1, 'T1', 'B' union
select 3, 1, 'T1', 'C' union
select 4, 2, 'T1', 'D' union
select 5, 2, 'T1', 'E' union
select 5, 4, 'T1', 'G' union
select 6, 0, 'T2', 'F' union
select 7, 6, 'T2', 'B' union
select 8, 6, 'T2', 'C' union
select 9, 7, 'T2', 'D' union
select 10, 0, 'T3', 'B' union
select 11, 10, 'T3', 'A' union
select 12, 10, 'T3', 'C' union
select 13, 0, 'T4', 'H' union
select 14, 13, 'T4', 'I' union
select 15, 14, 'T4', 'B' union
select 16, 15, 'T4', 'J'
--select * from @project
Any help will be appreciated.
Thanks