Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8837649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:46:52+00:00 2026-06-14T09:46:52+00:00

If I run Select distinct CompanyID from Device I get 6 rows. If I

  • 0

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
 )
 )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:46:54+00:00Added an answer on June 14, 2026 at 9:46 am

    Assuming there are CompanyIDs in Company that are not in Device, the problem is the NULL value in the 6 from Device. Your NOT IN statement evaluates to UNKNOWN even if the CompanyID is not one of the 6. See this Q/A for more details: NOT IN clause and NULL values

    Edit: To avoid this try altering your subquery to:

    SELECT DISTINCT CompanyID FROM  Device WHERE CompanyID IS NOT NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run the following sql select distinct(type_) from Group_ I get group types
I have been trying to run the following query in SPARQL explorer SELECT DISTINCT
I have the following query: SELECT wm_concat(DISTINCT NAME) as Methods FROM TPM_TRAININGPLAN JOIN TPM_DELIVERYMETHODS
When I run the following query against a MSSQL 2000 SELECT DISTINCT(Email), (SELECT TOP
$sql = SELECT DISTINCT Branch FROM student_main; $result = mysql_query($sql); $row_num = mysql_num_rows($result); $rows
The following very simple query select distinct guid, browser_agent from tblMyGlossary where browser_agent is
When I run this query I get more rows than from a similar query
I'm trying to run the following MySQL query: SELECT * FROM user u JOIN
MS ACCESS SQL DELETE * FROM Lane_Details WHERE Lane_Details.Week not in(SELECT DISTINCT TOP 3
I want to run this query: SELECT DISTINCT ON (address_id) purchases.address_id, purchases.* FROM purchases

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.