title: Comparing two data sets in SQL
body: <p>I am wishing to compare two sets of data using SQL wherever possible. Please consider the following data structures:</p>
  
  <pre><code>tbl_users:
  +---------+----------+
  | user_id |   avatar |
  +---------+----------+
  |    1    | test.jpg |
  |    2    | 1234.jpg |
  +---------+----------+
  
  tbl_shortlists:
  +------+--------+
  |  id  |  owner |
  +------+--------+
  |   1  |    1   |
  |   2  |    2   |
  +------+--------+
  
  tbl_shortlist_items:
  +---------+--------------+
  | item_id | shortlist_id |
  +---------+--------------+
  |    1    |       1      |
  |    2    |       1      |
  |    3    |       1      |
  |    1    |       2      |
  |    2    |       2      |
  +---------+--------------+   
  </code></pre>
  
  <p>I wish to select the <code>tbl_users</code>.<code>user_id</code> and <code>tbl_users</code>.<code>avatar</code> where the shortlist owned by any user contains two or more of the same <code>item_id</code> as the current owner. So, let's assume I am looking up the user_id 1, with the above data structure. Since the Shortlist with the ID shares two items with <code>shortlist_id</code> 1 (i.e. user 1's shortlist), I would like to return <code>user_id</code> = 2 and <code>avatar</code> = 1234.jpg.</p>
  
  <p>I am at a loss as to how to do this in pure SQL. I was thinking that it might be possible to use <code>IN()</code>, but I don't know if that would work.</p>
  
  <p>Here's some pseudo-code to hopefully explain a little better what I would like:</p>
  
  <p>Select user_id and avatar 
  for each shortlist that contains two or more item_ids that are in the shortlist 
  that is owned by user_id = 1.</p>