我有tbl_user,tbl_friendship
- tbl_user
uid username
1 Joun
2 Bun
3 Meu
4 Nux
5 Zii
- tbl_friendship
friend_1 friend_2 status
1 2 1
1 3 1
1 4 0
5 1 1
2 3 1
friend_1和friend_2是FK到tbl_user.uid
状态1表示friend_1和friend_2是朋友。 状态0表示friend_1向friend_2发送请求,但friend_2不接受请求。
如何向用户Joun(uid 1)显示所有朋友。预期结果是:
2
3
5
我试过
SELECT friend_1, friend_2 FROM tbl_friendship
WHERE status = 1 AND friend_1 = 1 OR friend_2 = 1
结果:
friend_1 friend_2
1 2
1 3
5 1