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.
For example, I have said table:
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
What is needing to be output is the lines that contain repeat flag_id's and only ones containing NO in their flag column, excluding the NO line itself(so only the lines with data that does not show NO). So in this case only output lines 2 and 7. I have already written something that would look like this:
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')>1
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.