sql Find data that does NOT exist in a subquery
I'm trying to find all records that do not match my criteria.
I have a one-to-many table where for each key combo (wbs1, wbs2, wbs3)
there may be many records. I'm trying to query this table for each combo,
and return the combo (wbs1, wbs2, wbs3) only when the table has no records
that match my "in" criteria.
But at the moment, my query seems to be returning all or nothing.
select distinct wbs1, wbs2, wbs3
from dbo.Registry
where not exists ( select wbs1, wbs2, wbs3, InspType
from Registry
where ISNULL(InspType,'') IN ('Test 1','Test 2')
)
What I'd like in the return is a list of wbs1,wbs2,wbs3 where in the table
"Registry" there are no entries that match the Test (InspType) criteria.
Thanks!
No comments:
Post a Comment