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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:46:37+00:00 2026-05-21T04:46:37+00:00

There’s a strange behaviour that is drive me crazy. I’ve a table of users

  • 0

There’s a strange behaviour that is drive me crazy.

I’ve a table of users and a table of permissions in an old SQL Server 2000 database.
This database is a mess, many tables have no PK and there are no relations between the tables… but I couldn’t fix it (and honestly I don’t think this is related to the problem I have).

Users:
IDRecord -> PK money
-- other fields

Permissions:
IDRecord -> money (is not a PK)
IDUser   -> money (refers to Users.IDRecord WITHOUT FK)
Function -> varchar
-- other fields

I want to get the User’s ids of the users without any permission.

My first approach was to write something as:

select distinct IDRecord 
from Users
where IDRecord not in (
    select IDUser from Permissions
)

That returns me no rows.

But I KNOW there are users without permissions, so I write a second query:

select distinct U.IDRecord 
from Users U
left join Permissions P
    on P.IDUser = U.IDRecord
where P.IDRecord is null

that correctly returns the users without permissions.

So, where’s the problem?

Why the first doesn’t work?

  • 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-05-21T04:46:37+00:00Added an answer on May 21, 2026 at 4:46 am

    This is expected behavior.
    It is expected because SQL has three-valued logic.
    In other words: for those users who have no permissions, there is no result (NULL) returned by your subquery.
    Your WHERE condition is not satisfied in those cases because a value can never equal nor not equal NULL.

    Alternatives:
    1) use a LEFT JOIN (as you have done), or
    2) use NOT EXISTS, e.g.:

    SELECT DISTINCT IDRecord 
      FROM Users u
     WHERE NOT EXISTS (
             SELECT 1 
               FROM Permissions p 
              WHERE p.IDUser = u.IDRecord
           );
    

    Edit: More detail on how 3VL can bite you if you’re not careful:
    A possibly counter-intuitive result occurs if you do something like this…

    ...
    WHERE a_column <> 'some value';
    

    Suddenly rows where a_column is NULL disappear from your results.
    To get them back you can do this:

    ...
    WHERE (a_column <> 'some value' OR a_column IS NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a column that exists in 2 tables. In table 1, this column
There is a website called Gild.com that has different coding puzzles/challenges for users to
There is a moment in my app, that I need to force to show
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There are two table s : one is the master and one the detail
There are a lot of blogs saying that a hasOwnProperty check should be used
There is a table view with three sections. The last section may contain many
There is this strange situation I'm fighting on. I have 3 pages, les call
There is a shared folder in my D drive as works ( D:\works ).
There is no doubt that MonoTouch is one of the great cross-compiler(s). Similarly, SenchaTouch

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.