I'm using Graph Table in SQL Server .
This is my table:
--Node Table
CREATE TABLE [dbo].[Users]
(
[ID] [int] NOT NULL Primary key,
[FName] [nvarchar](100) NULL,
[LName] [nvarchar](100) NULL
)AS NODE
--Edge Table
CREATE TABLE [dbo].[FriendsOf] AS EDGE
How can I select all User1 friend of User2 and User2 is friend of User3
and User1 and User3 don't have direct Edge
between them.
I can write this query like this :
select distinct
u1.FName + ' ' + u1.LName as FirstFullName,
u2.FName + ' ' + u2.LName as SecondFullName,
u3.FName + ' ' + u3.LName as ThirdFullName
from
Users u1, FriendsOf fo1, Users u2, FriendsOf fo2, Users u3
where
match(u1-(fo1)->u2-(fo2)->u3)
and not exists(select 1 from friendsof fof
where (fof.$from_id = u1.$node_id and fof.$to_id = u3.$node_id) or (fof.$from_id = u3.$node_id and fof.$to_id = u1.$node_id)
)
but I want to understand other way?
i want to use code like this :
select distinct u1.FName + ' ' + u1.LName as FirstFullName, u2.FName + ' ' + u2.LName as SecondFullName,u3.FName + ' ' + u3.LName as ThirdFullName
from Users u1 , FriendsOf fo1 , Users u2 , FriendsOf fo2 , Users u3 , FriendsOf fo3,, FriendsOf fo4
where match(u1-(fo1)->u2-(fo2)->u3) and (not match(u1-(fo3)->u3) or not match(u3(fo4)->u1))
Please help me solve this problem.