0

I am using SQL Server 2008

I have a table like :

To_FRIEND | FROM_FRIEND      | FOR_FRIND
1         | 2                |3
1         | 5                |2 
1         | 9                |5

I need inner or recursion query to give me the related friends of Friend No 1

like

FRIENDS RELATED 
2   
3     
5
9

explination

4

2 回答 2

1

这是你想要的吗?

select from_friend
from t
where to_friend = 1
union
select for_friend
from t
where to_friend = 1;

它返回你想要的,但似乎不需要递归。

于 2013-11-07T02:38:37.797 回答
0
with cte as
(
select [from-friend]
from [dbo].[stk-stuff]
where [to-friend] = 1
union
select [for-friend]
from [dbo].[stk-stuff]
where  [to-friend]= 1
) 

select * from cte
于 2013-11-07T04:12:10.727 回答