स्पष्टीकरण के बाद (और वास्तव में "आपसी" भाग पढ़ना):
SELECT a.friendID
FROM
( SELECT CASE WHEN userID = $id
THEN userID2
ELSE userID
END AS friendID
FROM friends
WHERE userID = $id OR userID2 = $id
) a
JOIN
( SELECT CASE WHEN userID = $session
THEN userID2
ELSE userID
END AS friendID
FROM friends
WHERE userID = $session OR userID2 = $session
) b
ON b.friendID = a.friendID