SELECT id, name
FROM users
WHERE id IN (
SELECT friend_id
FROM user_relationships
WHERE user_id IN ( 1, 2 )
GROUP BY friend_id
HAVING COUNT(friend_id) >= 2
)
nebo s jedním připojením:
SELECT friend_id, name
FROM user_relationships r
INNER JOIN users u ON r.friend_id = u.id
WHERE user_id IN ( 1, 2 )
GROUP BY friend_id
HAVING COUNT(friend_id) >= 2