title: SQL select rows with only a certain value in them
body: <p>I have a table as such</p>
  
  <pre><code>Col 1 Col 2 Col 3
  1       A     1
  2       A     2
  3       B     1
  4       C     1
  5       C     2
  6       D     1
  </code></pre>
  
  <p>How do I only get <strong>unique</strong> rows which have Col 3 = 1?</p>
  
  <p>I want to get rows 3 and 6 (Col 2 = B and D respectively). I do not want A nor C since they have Col 3 = 2 as well.</p>
  
  <p>I've tried something along the lines of:</p>
  
  <p><code>select col 2 from table group by col 2 having count(col 3) = 1</code></p>
  
  <p>But that only brings up Col 2 for results so I'm uncertain if Col 3 contents = 1 or not.</p>
  
  <p><strong>EDIT:</strong> Sorry guys maybe I've not worded my question clearly. I want to get all of the rows of Col 2 which contain only Col 3 = 1 <em>AND ONLY 1</em>.</p>
  
  <p>So if I tried WHERE <code>Col 3= 1</code>, it would return 4 rows because A has 1. But since A also has a row where Col 3 = 2, I do not want that, same for C. From this example table, I would want the end result to only show 2 rows, B and D.</p>
  
  <p>My example table is an example, I actually have about 5000 rows to filter through, otherwise I'd do as you guys have suggested :)</p>