Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Help in creating a query

Author  Topic 

vondiplo
Starting Member

8 Posts

Posted - 2008-12-03 : 13:59:59
Hello all,

I've got a table of users, and another table of 'friendships'. For two given users, I want to be able to say if how many levels of mutual friends they have.

Explanation, assume:
Person A
Person B
Person C

Person A is friends with B, and person B is friends with C, that means that person A and C are friends of second degree. I want to be able to map my small database to friendship levels. Does anyone have an idea how to do so?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-03 : 15:17:23
Yes. See post http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=73079
and http://weblogs.sqlteam.com/peterl/archive/2008/11/27/Expand-network-using-CTE-without-circular-reference.aspx


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

vondiplo
Starting Member

8 Posts

Posted - 2008-12-05 : 08:36:21
Thank you very much Peso, a nice and elegent solution. I did notice you didn't use an recursion, which was my approach. Simplifies it greatly. How would you solve it with recursion though?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-05 : 09:13:12
The CTE uses recursion...



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

vondiplo
Starting Member

8 Posts

Posted - 2008-12-05 : 09:24:26
Sorry for nudging. You've been of great help. Thank you again. Though,what would be the equivalent of CTE in oracle PLSQL ?
Go to Top of Page
   

- Advertisement -