I have this table that I use (but not only) to store friends in a database:
user_1 | user_2 | status
where the "status" can be -1.0 or 1. Here we will only consider cases when the status is "0" (expected for user_1) or "1" (approved by user_2). I have the following query to search for pending / approved friends for this user $:
SELECT user_1,user_2,status FROM Friends WHERE (user_2 = '$user' OR user_1 = '$user') AND status >= 0;
The goal is to modify the request to also say if a given $ user2 is a regular (approved) friend of $ user1 and every (approved) friend of $ user1.
After some research, I realized that a left join will do the trick by setting the other field to NULL (if there is no mutual) or $ user2. I would like to do it effectively. I tried a few shots, but did not succeed.
Thanks in advance for your help.
EDIT: for example, let's say we have the following entries:
a | b | 1 c | a | 1 c | b | 1 a | d | 1
I want to list the friends of 'a' and for each friend f 'a', check if 'b' is a regular friend of f and 'a'. In addition, f = / = b for the mutual test. The result of such a query would be:
a | b | 1 | NULL c | a | 1 | b a | d | 1 | NULL
Let me know if you need more clarification.
source share