I just wanted to find the database structure in MySQL to get all friends of friends of friends and the corresponding query to get them. (friends links are bidirectional)
I found a couple of posts related to this, but performance worries me:
Structure 1
Many posts offer a structure in which you have a table in which each row represents a friendship link, for example:
CREATE TABLE `friends` (
`user_id` int(10) unsigned NOT NULL,
`friend_id` int(10) unsigned NOT NULL,
)
saying that user '1' has three friends '2', '3', '4', and user '2' has two friends '1', '5'. Your friend’s table will look like this:
user_id | friend_id
1 | 2
1 | 3
1 | 4
2 | 1
2 | 5
: SQL, , , '1' (1,2,3,4,5)
: fb- 140 . .
20.000 , 3 .
2
:
CREATE TABLE `friends` (
`user_id` int(10) unsigned NOT NULL,
`friend_1` int(10) unsigned NOT NULL,
`friend_2` int(10) unsigned NOT NULL,
`friend_3` int(10) unsigned NOT NULL,
`friend_4` int(10) unsigned NOT NULL,
....
)
( ):
user_id | friend_1 | friend_2 | friend_3 | ...
1 | 2 | 3 | 4 |
2 | 1 | 5 | |...
20 000 .
: ,
Select * FROM friends as a
WHERE a.user_id
IN (
SELECT * FROM friends AS b
WHERE b.user_id = '1'
)
"# 1241 - 1 ". , , , ?
, . .
1)
, 2?
2)
?
2 , "join row with column" , . . - , , , .
!!