Here’s the scenario. I have a single SQL Server 2008 table – Products – with 2 columns: id and IsNotValid. The data would look something like this:
id IsNotValid
1 0
1 0
1 1
2 0
2 0
3 1
3 1
I would like a SQL statement that would return a result set that would return all the records (2) for the id=2 – in this case all the IsNotValid values for id=2 is 0. id=1 should not be returned as one of its IsNotValid records is 1. Similar for id=3. The data types are: id (int), IsNotValid (bit).
This should give you the results you need: