SELECT yt1.user, SUM(CASE WHEN yt1.answer = yt2.answer THEN 1 ELSE 0 END) AS howMuchAnswersInCommon FROM yourTable yt1 INNER JOIN yourTable yt2 ON yt1.question = yt2.question WHERE yt2.user = 1 AND yt1.user != 1 GROUP BY yt1.user ORDER BY howMuchAnswersInCommon DESC ;
This will give you the one with the most common answers to user 1 on top.
Test data:
/* create table yourTable (user int, question int, answer int); insert into yourTable values (1, 1, 3), (1, 2, 3), (1, 3, 2), (1, 4, 5), (1, 5, 1), (2, 1, 2), (2, 2, 3), (2, 3, 1), (2, 4, 5), (2, 5, 3), (3, 1, 3), (3, 2, 3), (3, 3, 4), (3, 4, 5), (3, 5, 3), (4, 1, 5), (4, 2, 3), (4, 3, 2), (4, 4, 5), (4, 5, 1); */
CONCLUSION:
user howMuchAnswersInCommon 4 4 3 3 2 2