I have an table like this
Id Name ReportingId
==
1 Stala Null
2 Coma 1
3 Rita 1
4 Rosy 2
5 sss 4
I want a recursive query to find all reporting ids in single column.
For example for id 5 the output should be up to null always
4
2
1
null
Here’s an example using a recursive common table expression (CTE):
Example on SQL Fiddle.