title: select distinct records where multiple rows exist for one ID based on values in another column
body: <p>So I'm not exactly sure if my title is correct or misleading.  It sounds simple, but I can't figure it out and haven't found a good example.</p>
  
  <p>I want to select the distinct ID's from a table where the ID does not match to a certain code. For instance I have tableA as below:</p>
  
  <p>tableA</p>
  
  <pre><code>ID          Code 
  ====        ==== 
  1            AAA 
  1            BBB 
  1            CCC 
  2            AAA 
  2            DDD 
  2            EEE 
  3            BBB 
  3            GGG 
  3            HHH
  </code></pre>
  
  <p>The only result I would like to return is ID 3 since ID 1 and ID 2 match to code 'AAA'.</p>
  
  <p>I've tried:</p>
  
  <pre><code>SELECT disctinct(ID) from tableA where code &lt;&gt; 'AAA' 
  </code></pre>
  
  <p>but this returns ID 1, 2, and 3.  I'm not sure if a group by would work either because I don't even want ID 1 and 2 to be returned.</p>