在mysql中获取好友列表 [英] get friend list in mysql
本文介绍了在mysql中获取好友列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张像这里的桌子:
I have a table like here :
friend : (userid , friendid)
所以,如果 user_a
是 user_b
的朋友,我会将下面的行加载到表中
so , if user_a
is friend with user_b
, I will load the row below into table
user_a , user_b
和我不会将 usar_b , user_a
插入 table .
and I DO NOT insert usar_b , user_a
into table .
那么如何通过 mysql 查询获取 user_b 的好友列表?
so how can I get friend list of user_b with mysql query ?
推荐答案
假设你想要 userA 的朋友
需要获取userA的所有好友,将其与好友为userA的所有用户联合.
Let's say you want userA's friends
You need to get all the friends of userA, Union it with all the users whose friend is userA.
假设用户 A 的 ID 是 1001
查询将是
Assuming that userA's ID is 1001
the query will be
select UserID from Friends
where FriendID = 1001
Union All
select FriendID from Friends
where UserID = 1001
这篇关于在mysql中获取好友列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文