title: MYSQL - calculating differences within a single table
body: <p>I'm looking for a way to calculate differences between integers within a single table.</p>
  
  <p>I'm planning a MYSQL table that looks like this:</p>
  
  <pre><code>user    question    answer
  
  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
  </code></pre>
  
  <p>Each user (in this example) has answered 5 questions, giving an answer on a scale of 1 to 5.</p>
  
  <p>What I'm looking to work out is which of the users 2, 3 and 4 have given answers that are most similar to those provided by user 1. </p>
  
  <p>What I have in mind is calculating the difference between the answers given by each user for each question, in comparison to those of user 1, and then adding up those differences. </p>
  
  <p>The user with the lowest number after that addition would be most similar to user 1.</p>
  
  <p>I'm sorry to say that I don't really know where to begin constructing a query that does this efficiently and was wondering if anyone could point me in the right direction? 
  I'm also open to any suggestions for any better or more logical way to build the same results. </p>