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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:15:00+00:00 2026-06-05T01:15:00+00:00

I am using the following query: select count(*) from Table1 where CurrentDateTime>’2012-05-28 15:34:02.403504′ and

  • 0

I am using the following query:

select count(*) from Table1 where CurrentDateTime>'2012-05-28 15:34:02.403504' and Error not in ('Timeout','Connection Error');

Surprisingly, this statement doesnot include the rows having Error value as NULL.My intention is to filter only rows with Error value as ‘Timeout’ (or) ‘Connection Error’. I need to give an additional condition( OR Error is NULL) to retrieve the correct result.

Why is MYSQL filtering out results with NULL values?
I thought that IN keyword would return a boolean result (1/0) and now i understand that some MYSQL keywords doesnt return boolean values,it might return NULL too….but Why is it treating NULL as special?

  • 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-05T01:15:02+00:00Added an answer on June 5, 2026 at 1:15 am

    This :

    Error not in ('Timeout','Connection Error');
    

    is semantically equivalent to:

    Error <> 'TimeOut' AND Error <> 'Connection Error'
    

    Rules about null comparison applies to IN too. So if the value of Error is NULL, the database can’t make the expression true.

    To fix, you could do this:

    COALESCE(Error,'') not in ('Timeout','Connection Error');
    

    Or better yet:

    Error IS NULL OR Error not in ('Timeout','Connection Error');
    

    Or more better yet:

     CASE WHEN Error IS NULL THEN 1
     ELSE Error not in ('Timeout','Connection Error') THEN 1
     END = 1
    

    OR doesn’t short-circuit, CASE can somehow short-circuit your query


    Perhaps a concrete example could illustrate why NULL NOT IN expression returns nothing:

    Given this data: http://www.sqlfiddle.com/#!2/0d5da/11

    create table tbl
    (
      msg varchar(100) null,
      description varchar(100) not null
      );
    
    
    insert into tbl values
    ('hi', 'greet'),
    (null, 'nothing');
    

    And you do this expression:

    select 'hulk' as x, msg, description 
    from tbl where msg not in ('bruce','banner');
    

    That will output ‘hi’ only.

    The NOT IN is translated as:

    select 'hulk' as x, msg, description 
    from tbl where msg <> 'bruce' and msg <> 'banner';
    

    NULL <> 'bruce' can’t be determined, not even true, not even false

    NULL <> 'banner' can’t be determined, not even true not even false

    So the null value expression, effectively resolved to:

    can't be determined AND can't bedetermined
    

    In fact, if your RDBMS supports boolean on SELECT(e.g. MySQL, Postgresql), you can see why: http://www.sqlfiddle.com/#!2/d41d8/828

    select null <> 'Bruce' 
    

    That returns null.

    This returns null too:

    select null <> 'Bruce' and null <> 'Banner'
    

    Given you are using NOT IN, which is basically an AND expression.

    NULL AND NULL
    

    Results to NULL. So it’s like you are doing a: http://www.sqlfiddle.com/#!2/0d5da/12

    select * from tbl where null
    

    Nothing will be returned

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

Sidebar

Related Questions

I'm using Oracle 10.2 and have the following query: select h.company, count(*) from history
I am using the following query to get the count from multiple tables:- SELECT
I am using following SQL Query: SELECT `comment`.`id` AS `comment_id` , count( `comment_likes`.`comment_id` )
i've been using the following query: select LEN(columnname) as columnmame from dbo.amu_datastaging This works,
I'm using the following query to select users from my 'users' table with the
I am using the following query to select wait times from the table wait_times
I am using the following query in my database, SELECT b.sales_id,b.category_id,b.sale_starts,b.sale_ends FROM tbl_sales b
I am trying to code the following query using Zend_Db api's: select * from
Using phpMyAdmin and running the following query I get 19 registers: SELECT * FROM
I'm executing the following query SELECT COUNT(*) FROM table WHERE field1='value' AND (field2 >=

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.