title: Matching interests(Nearest neighbour) search in SQL
body: <p>I'm trying to find users with similar set of interests, with the following schema.. </p>
  
  <pre><code>USERS - ID name etc
  
  Interests - ID UID PID
  </code></pre>
  
  <p>where ID is unique ID for Interests, UIS is user ID and PID is a product ID.  I have looked at other similar questions at SO, but none of them had an exact answer. </p>
  
  <p>Example- Let's say I'm interested in getting users with similar interest to John, and this is how to two tables look like ... </p>
  
  <pre><code>ID  Name
  11  John
  12  Mary
  13  Scott
  14  Tim
  
  ID UID PID
  3  12  123
  4  12  231
  5  12  612
  6  13  123
  7  13  612
  8  14  931
  9  14  214
  10 11  123
  11 11  231
  12 11  781
  13 11  612
  </code></pre>
  
  <p>I would like a result with  in that order. </p>
  
  <p>I was thinking of doing a set intersection of the user I'm interested in with all other users. It doesn't sound like a very good solution, because it will have to be done everytime a user adds interest or another user is added. Its a small project, and as of now I'll be limiting users to 100. I still think that the above approach will not be efficient at all as it will take 100<sup>2</sup> time.</p>
  
  <p>Can someone guide me in the right direction? What are the possible solutions, and which one will be the best with above given constraints. I'm looking at <a href="http://www.cs.umd.edu/~mount/ANN/" rel="nofollow">ANN</a> to see if I can use that. </p>