Change... AND t.testname is not null AND (st.testid <> 7)to AND t.testname is not null AND (st.testid <> 7) AND (st.testid <> 5)...and you should be all set.