title: SELECTING with multiple conditions on different columns
body: <p>Alright, I believe I'm on the right track but having some difficulty getting the desired results. I'm attempting to check two different columns in a table for a specific flag, then relating said flag to the second column.</p>
  
  <p>For example, I have said table:</p>
  
  <pre><code>ID   date       flag      flag_id 
  -----------------------------------
  1  09/25/2017   NO        0001
  2  09/25/2017   OTHER     0002
  3  09/25/2017   NO        0002
  4  09/25/2017   OTHER     0003
  5  09/25/2017   OTHER     0004
  6  09/25/2017   NO        0005
  7  09/25/2017   OTHER2    0005
  8  09/25/2017   OTHER     0006
  </code></pre>
  
  <p>What is needing to be output is the lines that contain repeat <code>flag_id</code>'s and only ones containing <code>NO</code> in their flag column, excluding the <code>NO</code> line itself(so only the lines with data that does not show <code>NO</code>). So in this case only output lines 2 and 7. I have already written something that would look like this:</p>
  
  <pre><code>SELECT distinct
     t1.ID,
     t1.date,
     t1.flag,
     t1.flag_id,
  FROM table1 t1
  WHERE (SELECT COUNT(*)
     FROM table1 t2
     WHERE t1.flag_id = t2.flag_id
     AND t1.flag != 'NO'
     AND t2.flag = 'NO')&gt;1
  </code></pre>
  
  <p>Making a beginner mistake here, and mind you I am still very new to this, so an explanation on why this is not working or why something else works would be appreciated.</p>