title: Taking intersection of data in Hive
body: <p>I have in hive the following data:</p>
  
  <pre><code>userid cityid
  1      15
  2      15
  1      7
  3      15
  2      8
  3      9
  3      7
  </code></pre>
  
  <p>And I want to keep only the userid's that have a cityid 15 and a cityid 7 (in my example, it would be userid's 1 and 3).
  I tried:</p>
  
  <pre><code>select userid from table where cityid = 15 and userid in (select userid from table where cityid = 7);
  </code></pre>
  
  <p>But with hive it is not working.
  Can somebody help?</p>
  
  <p>Thanks!</p>