SQL to get friends AND friends of friends of a user

后端 未结 2 1222
醉话见心
醉话见心 2021-02-03 12:56

My MySQL tables structure is like this.

USER
int id
varchar username

FRIEND_LIST
int user_id
int friend_id

For each friend relationship I inse

2条回答
  •  一生所求
    2021-02-03 13:58

    SELECT f1.user_id, f1.friend_id FROM
    friends_info f1
    WHERE f1.user_id = 1 OR
    f1.user_id IN
    (
     select f2.friend_id
     from friends_info f2
     where f2.user_id = 1
    )
     ORDER BY user_id
    

提交回复
热议问题