Hi
I have this problem. Given a users
table that consists of users' username in a social network and friends
table that contain a user's name and a user's friendname like below...
username friendname
John Thomas
Chris James
... I'm trying to write an SQL statement that will if a user is in my network. In other words is that user a friend or friend of friends?
I've been dancing around this problem and could only come up with this query:
SELECT f2.username, f2.friendname
FROM friends f2
WHERE f2.username IN (
SELECT f1.friendname
FROM friends f1
WHERE f1.username = 'Thomas')
AND f2.friendname <> 'user1'
AND f2.friendname = 'user2';
It basically check if a user if is a friend of my friend i.e. just return null if false.
Trying to figure out how I can expand to go through all my network of friend. I mean not just friend of my friend.