title: sql intersect with dynamic input set
body: <p>I'm trying to figure out how to get the intersection of a dynamic input set. Here is a very simplified example.</p>
  
  <p><strong>company_status</strong> table:</p>
  
  <pre><code>COMPANY | STATUS
  ----------------
    Big   |   1
  Notused |   0
   Small  |   1
  </code></pre>
  
  <p><strong>company_country</strong> table:</p>
  
  <pre><code>COMPANY | COUNTRY
  -----------------
    Big   |   CA
    Big   |   US
  Notused |   CA
  Notused |   FR
   Small  |   US
   Small  |   IT
  </code></pre>
  
  <h3>What I want is the intersection of the countries for only certain companies.</h3>
  
  <p>If I select only companies where <code>status = 1</code>, here is my expected output:</p>
  
  <blockquote>
    <p>US</p>
  </blockquote>
  
  <p>If I select only companies where <code>status = 0</code>, here is my expected output:</p>
  
  <blockquote>
    <p>CA<br>
    FR</p>
  </blockquote>
  
  <p>Taking the company_status table out of the equation, this is what I need:</p>
  
  <pre><code>select country from company_status where company = 'Big'
  intersect
  -- ... (here is where the dynamic part comes in)
  intersect
  select country from company_status where company = 'Small';
  </code></pre>
  
  <p>But how do I add company_status into this?</p>