Q&A for those committed to a vegan or vegetarian lifestyle and anyone interested in learning more
declare @T table(ID int, ParentID int, DATA char(1)); insert into @T values (1, -1, 'a'), (2, 1, 'b'), (3, 2, 'c'), (4, 3, 'd'), (5, 3, 'f'); declare @id int select @id=3 select * from @T t where t.id = @id union all select t1.* from @T t inner join @T t1 on t.parentid = t1.id where t.parentid = @id