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 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

Sorry, I'm sure making a silly mistake, but did not work out. I'm compiling
I'm sure I'm making some kind of silly mistake here, but when converting a
The following is some code for making sure people can't submit if the value
I'm accessing a database in steps, and making sure that I dispose of all
I'm trying to add a horizontal LinearLayout programmatically, making sure the second child takes
How to generate random integers but making sure that they don't ever repeat? For
Stupid question, but just making sure here: When should I use TCP over HTTP?
Perhaps it is a silly question but I want to be sure about it.
Possible Duplicate: Making sure a web page is not cached, across all browsers I
I am in the process of making sure our MVC app catches all exceptions

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.