Try this double independent connection for mutual friendship:
SELECT Friend_1, Friend_2, COMMON FROM ( SELECT f2.NAME_1 AS Friend_1 ,f1.NAME_2 AS Friend_2 ,f2.Name_2 AS COMMON FROM friends f1 INNER JOIN friends f2 ON f1.NAME_1 = f2.NAME_2 WHERE f1.accepted = 1 AND f2.accepted = 1 ) T INNER JOIN FRIENDS F3 ON (F3.Name_1 = Friend_1 AND F3.Name_2 = Friend_2) OR (F3.Name_2 = Friend_1 AND F3.Name_1 = Friend_2) WHERE F3.ACCEPTED <> 0 AND Friend_1 = 'John' AND Friend_2 = 'Jimmy'
COMMON is a mutual friend.
Related SQL Fiddle
Note Iβm not sure that this structure is the best for such an attitude, you have the rules of mutual friendship, refusal of friendship, but it looks like you know nothing about this information. Do you know only partial information or is it your storage system / architecture?
source share