SQL gurus
I have a table structure as follows
Id Name IdPartner
Id1 name1
Id2 Name2 Id1
Id3 name3 Id1
Id4 name4 Id2
Id5 name5 Id3
I need to write a query that would recursively loop through the table to find the partners.
I.e Given an Id say Id1 here, I need to pull out all the Names where Id1 is listed as a partner, So my query need to pull up Name3 and Name2. Subsequently in the same query I also need to pull the names where Name3 and Name2 are also listed as partners. So in this case if I give the input to the SP as Id1 I should effectively get a list that read as below
Id Name
Id2 name2
Id3 name3
Id4 name4
Id5 name5
I havent worked with recursively getting the data in SQL. Someone told me I could use a common table expression, but I fail to see how that would help me. I have been breaking my head over this for over a day and all I can come up with is the idea of using a cursor.
Any help in this regard helps
The following returns the related, but not requested, rows: