I have a legacy database that I am working with a basic column layout as such:
SampleID
CompanyID
CompanyApplication
CompanyTest1
...
CompanyTest25
Not normalized in the least, this is causing a bit of a data mining issue.
I need to get the CompanyIDs (Grouped By) where the CompanyApplication field = “Registration” but this company has none of the CompanyTest(n) fields selected for any SampleID.
The problem is, there are CompanyIDs that have both CompanyApplication and CompanyTest(n) records (multiple rows), but I want to get CompanyIDs that only have a CompanyApplication of Registration.
Data to help illustrate:
SampleID | CompanyID | CompanyApplication | CompanyTest1 | ... | CompanyTest25
------------------------------------------------------------------------
1 | 1 | Registration | | |
------------------------------------------------------------------------
2 | 1 | | True | |
------------------------------------------------------------------------
3 | 2 | Registration | | |
------------------------------------------------------------------------
4 | 2 | Registration | | |
------------------------------------------------------------------------
5 | 3 | | True | |
------------------------------------------------------------------------
6 | 3 | | | | True
I only want to retrieve rows 3 and 4 because they ONLY have Registration and no other testing.
We could start by selecting all of the rows that you are trying to exclude, and then use a
NOT EXISTSto skip overCompanyIDs that are in that query.