SQL Friends List Query

前端 未结 2 1094
难免孤独
难免孤独 2021-01-22 00:56

I am new to this database SQL language so I will try to make it as simple as possible. (I am using MySQL Workbench)

I have a table for User and I want multiple users to

2条回答
  •  情深已故
    2021-01-22 01:34

    Use UNION ALL to get all friends, parameterize this query:

    select friend_user_id as friend_id from friends f where f.user_id = 2 --parameter
    union all
    select user_id as friend_id from friends f where f.friend_user_id = 2 --parameter
    

提交回复
热议问题