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

  • Home
  • SEARCH
  • 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 82555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:38:07+00:00 2026-05-10T21:38:07+00:00

I am sure making a silly mistake but I can’t figure what: In SQL

  • 0

I am sure making a silly mistake but I can’t figure what:

In SQL Server 2005 I am trying select all customers except those who have made a reservation before 2 AM.

When I run this query:

SELECT idCustomer FROM reservations  WHERE idCustomer NOT IN    (SELECT distinct idCustomer FROM reservations     WHERE DATEPART ( hour, insertDate) < 2) 

I get 0 results.

But

SELECT idCustomer FROM reservations  

returns 152.000 results and the ‘NOT IN’ part:

SELECT distinct idCustomer FROM reservations  WHERE DATEPART ( hour, insertDate) < 2 

returns only 284 rows

  • 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. 2026-05-10T21:38:08+00:00Added an answer on May 10, 2026 at 9:38 pm
    SELECT distinct idCustomer FROM reservations WHERE DATEPART ( hour, insertDate) < 2   and idCustomer is not null 

    Make sure your list parameter does not contain null values.

    Here’s an explanation:

    WHERE field1 NOT IN (1, 2, 3, null) 

    is the same as:

    WHERE NOT (field1 = 1 OR field1 = 2 OR field1 = 3 OR field1 = null) 
    • That last comparision evaluates to null.
    • That null is OR’d with the rest of the boolean expression, yielding null. (*)
    • null is negated, yielding null.
    • null is not true – the where clause only keeps true rows, so all rows are filtered.

    (*) Edit: this explanation is pretty good, but I wish to address one thing to stave off future nit-picking. (TRUE OR NULL) would evaluate to TRUE. This is relevant if field1 = 3, for example. That TRUE value would be negated to FALSE and the row would be filtered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I must be dumb (and I'm sure I am making mistake but can't figure
I'm sure I'm making some kind of silly mistake here, but when converting a
Not sure if the title is quite right for the question but I can't
I am trying to create a way of making sure that every space has
is there any way of making sure that, one user is logged in only
What's the best practice for making sure that certain ajax calls to certain pages
I'm making a simple Image Debugger Visualizer. Code is below. I'm not sure if
Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I
Not sure how to ask a followup on SO, but this is in reference
Not sure what exactly is going on here, but seems like in .NET 1.1

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.