Perhaps I have this wrong but I thought this query would use recursion however I can't seem to write it correctly. Here is the sample data:
DECLARE @Friends TABLE
(
[person_id] [int] NOT NULL,
[first_name] [varchar](50) NOT NULL,
[favorite_color] [varchar](50) NOT NULL,
[best_friend] [varchar](50) NOT NULL
)
INSERT @Friends VALUES (1, 'John', 'blue', 'Mark')
INSERT @Friends VALUES (2, 'Mark', 'green', 'Sally')
INSERT @Friends VALUES (3, 'David', 'purple', 'John')
INSERT @Friends VALUES (4, 'Sally', 'red', 'Rose')
INSERT @Friends VALUES (5, 'Stephanie', 'blue', 'Rose')
INSERT @Friends VALUES (6, 'Rose', 'yellow', 'David')
Now I need to list each person's name in first column then their BEST FRIENDS favorite color in the second.
My thought was to use a cte and the initialization query would get the list of names and the recursion would get their best friends color.
However now I am unsure how to write the recursion part to find the best friends color?
Not looking for anyone to do my homework just trying to get headed in the right direction.
TIA