How do I create a recursive query in MSSQL 2005?

后端 未结 4 454
心在旅途
心在旅途 2021-01-30 14:31

Let\'s say I have the following table:

CustomerID ParentID Name
========== ======== ====
1          null     John
2          1        James
3          2        J         


        
4条回答
  •  一整个雨季
    2021-01-30 15:20

    Unless I'm missing something, recursion isn't necessary...

    SELECT d.NAME FROM Customers As d
    INNER JOIN Customers As p ON p.CustomerID = d.ParentID
    WHERE p.Name = 'James'
    

提交回复
热议问题