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 8064581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:24:47+00:00 2026-06-05T11:24:47+00:00

Found the best answer to my question here: NOT IN clause and NULL values

  • 0

Found the best answer to my question here: NOT IN clause and NULL values

Neither of the following two queries return any results:

select upc 
from   staging..posrecords 
where  upc not in (select upc from mrs..items)

select upc 
from   staging..posrecords 
where  upc in (select upc from mrs..items)

Both of the following queries do return results:

select upc from staging..posrecords

select upc from mrs..items

Given that the latter two queries do both return results, I don’t understand how it’s possible that neither of the first two queries return any results whatsoever. Maybe it’s late and I’m just missing something really obvious, but I’m about as stumped as I can be right now.

Furthermore, the following query also does returns results

select upc 
from mrs..items 
where upc not in (select upc from staging..posrecords)

That being the case, I am even more baffled as to why the very first query up above doesn’t return any results.

  • 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-05T11:24:49+00:00Added an answer on June 5, 2026 at 11:24 am

    Reason: When the subquery contains NULL values in a column it always returns NULL.

    1 OR 2 OR NULL
    TRUE OR NULL
    NULL
    

    More Details with example.

    http://explainextended.com/2009/09/15/not-in-vs-not-exists-vs-left-join-is-null-sql-server/

    The reason could be you have NULL values in upc column in mrs...items table, Try following query.

        select upc 
        from   staging..posrecords 
        where  upc not in (select upc from mrs..items where upc is not null)
    
        select upc 
        from   staging..posrecords 
        where  upc in (select upc from mrs..items where upc is not null)
    

    Try using Not exists

        select upc 
        from staging..posrecords 
        where not exists ( select upc from mrs..items 
        where mrs..items.ups = staging..posrecords.upc)
    
    
        select upc 
        from   staging..posrecords 
        where not exists(select upc from mrs..items 
        where mrs..items.upc=staging..posrecords.upc)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't exactly found the answer to this, maybe there is no best one.
I found another similar question: Best way to download images from XML content in
I searched through here as best I could and though I found some relevant
I've searched through the site and haven't found a question/answer that quite answer my
While I found this question being answered here on SW several times, I didn't
I was following the answer to another question , and I got: // itemCounter
I have found many questions here about storing values in viewstate, but haven't found
Per an answer to a previous question (answer here: SQL/Database Views in Grails ),
I've searched around for answers to this question, but not found anything quite on
I found this question , which has an answer, but facebook changed the token

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.