title: SQL select distinct where exist row for each id in other table
body: <p>I have table A and B with a relationship: A n&lt;->1 B relationship.</p>
  
  <p>They are joined over field A.b = B.id, where B.id is unique</p>
  
  <p>I have a parameter which is a bunch of ids of B.</p>
  
  <p>I want to get distinct A.id that have <em>all</em> given B.ids assigned.</p>
  
  <p><strong><em>Example:</em></strong></p>
  
  <p><strong>Table B</strong></p>
  
  <pre><code>| id | ...
  | 1  |
  | 2  |
  | 3  |
  </code></pre>
  
  <p><strong>Table A</strong></p>
  
  <pre><code>| id |  b  | ...
  | 1  |  1  |
  | 1  |  2  |
  | 1  |  3  |
  | 2  |  1  |
  | 2  |  2  |
                 &lt;-- id=2 is not assigned to b=3 !
  | 3  |  1  |
  | 3  |  2  |
  | 3  |  3  |
  </code></pre>
  
  <p><strong>Expected result for parameter B.ids="1,2,3"</strong>: 1, 3 (2 misses the required B.id=3)</p>
  
  <p>How can I do this?</p>