I have a MySQL table like this:
| USER | FRIEND |
-----------------
| 1 | 2 |
| 2 | 1 |
| 1 | 16 |
| 16 | 1 |
| 1 | 4 |
I need to write a MySQL query to list all (accepted) friends of user 1, in this case, it should return 2 and 16, but not 4, as that friendship isn’t accepted.
Is there any 1-query way to do this?
Assuming that an accepted fried is a friend that has a two entries in the table, one from the user to the friend and another from the friend to the user(as you explained with the sample data in your question), then you can do this:
SQL Fiddle Demo
This will give you: