SQL table for friends, mutual friends, friends friends etc
Tag : sql , By : user90210
Date : March 29 2020, 07:55 AM
This might help you I would suggest to go for two way relationship. It's flexible ans it's only extra work while inserting and deleteing the records. The benefits that I see is:
|
How to count a Facebook app user's friends of friends of friends
Date : March 29 2020, 07:55 AM
this will help No, this can't be done using the Graph API or FQL. The furthest you can get is to select information from the user table relating to your friends, such as their friends count, by doing a subselect in your query like this: SELECT uid, friend_count
FROM user
WHERE uid IN (
SELECT uid1
FROM friend
WHERE uid2 = me()
)
SELECT uid1
FROM friend
WHERE uid2 in (
SELECT uid1
FROM friend
WHERE uid2 = me()
)
{
"error": {
"message": "Can't lookup all friends of 36807322. Can only lookup for the logged in user or the logged in user's friends that are users of your app.",
"type": "NoIndexFunctionException",
"code": 604
}
}
|
Most efficient way to find friends of friends, excluding friends
Tag : mysql , By : Patastroph
Date : March 29 2020, 07:55 AM
To fix this issue Let's say I have a table called friends, and for each friendship, I add two entries. For example, if users 1 and 2 are friends, we will have: , Add an outer join with your own friends so you can filter them out. SELECT f2.uid2 FROM friends f1
JOIN friends f2 ON f1.uid2 = f2.uid1
LEFT JOIN friends f3 ON f3.uid2 = f2.uid2 AND f3.uid1 = 'YourID'
WHERE f1.uid1='YourID'
AND f2.uid2!='YourID'
AND f3.uid2 IS NULL
|
SQL: Suggested friends with 1 degree of separation where my friends share more than 2 mutual friends
Tag : mysql , By : user150744
Date : March 29 2020, 07:55 AM
Hope this helps Missing the reciprocal relationship does make this much harder. It requires checking both directions of the relationship. You seem to be pursing a a strategy of using union to reconstruct both sides of the relationship. Alternatively, you can use exists and subqueries. The following version finds entities that are not friends and that have at least two friends in common using exists: select e.*
from entities e
where e.entity_id <> :user_id and
not exists (select 1
from friends f
where f.category <> 4 and
:user_id in (f.entity_id1, f.entity_id2) and
e.entity_id in (f.entity_id1, f.entity_id2)
) and
(select count(*)
from friends f1 join
friends f2
on f1.entity_id1 = f2.entity_id1 or
f1.entity_id1 = f2.entity_id2 or
f1.entity_id2 = f2.entity_id1 or
f1.entity_id1 = f2.entity_id2
where :user_id in (f1.entity_id1, f1.entity_id2, f2.entity_id1, f2.entity_id2) and
e.entity_id in (f1.entity_id1, f1.entity_id2, f2.entity_id1, f2.entity_id2)
) >= 2
|
mysql query to workout friends of friends who are not in my friends list
Date : March 29 2020, 07:55 AM
|