Question: Need help to write sql query Id is unique. NextID stores the noxt ID value. When NextID value is Null, there the path Ends. Input:

Need help to write sql query

Id is unique. NextID stores the noxt ID value. When NextID value is Null, there the path Ends.
Input:

ID NextID
1 5
2 Null
3 6
4 7
5 8
6 9
7 Null
8 Null
9 10
10 Null

 

Output:

a. 1 --> 5 --> 8
b. 2
C. 3 -->6 -->9 -->10
d. 4-->7
e. 8

 

Sample scripts:

 

 

 

INSERT Data VALUES   ('1','5'),   ('2','Null'),   ('3','6'),   ('4','7'),   ('5','8'),   ('6','9'),   ('7','Null'),   ('8','Null'),   ('9','10'),   ('10','Null')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!