Help using left outer joins in SQL...
Posted
by
Waffles
on Stack Overflow
See other posts from Stack Overflow
or by Waffles
Published on 2011-02-23T23:23:01Z
Indexed on
2011/02/23
23:25 UTC
Read the original article
Hit count: 681
I'm trying to create a list of people, their friends, and their friends of friends.
My table of people is this:
People:
NAME
Jow
Smith
Sandy
Phil
Friends
LIKER LIKEE
jow smith
smith jow
sandy phil
Now, what I want is a table like this:
User Friend FriendofFriend
Jow smith jow
Smith jow smith
sandy phil
phil
I'm trying to create a table using the following:
SELECT P.NAME, F.LIKEE, F2.LIKEE
FROM PEOPLE P
LEFT OUTER JOIN FRIENDS F
ON P.NAME = F.LIKER
LEFT OUTER JOIN FRIENDS F2
ON F.LIKEE = F2.LIKER
But the above isn't working. How can I get a table of people and their friends, regardless of whether or not they actually HAVE any friends?
© Stack Overflow or respective owner