If I run
Select distinct CompanyID from Device
I get 6 rows. If I run
Select CompanyID from Company
I get 8441 rows. If I run the following:
If I run
Select CompanyID
from Company where CompanyID NOT IN
(
Select distinct CompanyID from Device
)
I should get the 8435 companies that aren't in the original select statement, correct?
However, when I run this I get 0 rows. What is the issue here? One of the 6 results from above is null but that shouldn't matter.
Thanks!
edit: With Marc-s's help I was able to get the following statement to be what I needed, I still feel like there was an extra step in this query, anyone care to add to this?
DELETE from Company where CompanyID NOT IN
(
Select C.CompanyID
from Company C where C.CompanyID IN
(
Select distinct CompanyID from Device
)
OR CompanyID IN
(
Select distinct CustomerID from Device
)
OR CompanyID IN
(
Select distinct CompanyID from AssignedCompanies
)
)