Basic SQL logic of NOT and NULL values when using =












1















select * from dual where not (1=2 );


One row returned.



select * from dual where not ( 5=null);


No rows returned.



select * from dual where not (1=2 and 5=null);


Unexpectedly, row returned.



Am I missing something basic how NOT works?
Or how AND works?



Tried in Oracle 11 and 12.










share|improve this question



























    1















    select * from dual where not (1=2 );


    One row returned.



    select * from dual where not ( 5=null);


    No rows returned.



    select * from dual where not (1=2 and 5=null);


    Unexpectedly, row returned.



    Am I missing something basic how NOT works?
    Or how AND works?



    Tried in Oracle 11 and 12.










    share|improve this question

























      1












      1








      1








      select * from dual where not (1=2 );


      One row returned.



      select * from dual where not ( 5=null);


      No rows returned.



      select * from dual where not (1=2 and 5=null);


      Unexpectedly, row returned.



      Am I missing something basic how NOT works?
      Or how AND works?



      Tried in Oracle 11 and 12.










      share|improve this question














      select * from dual where not (1=2 );


      One row returned.



      select * from dual where not ( 5=null);


      No rows returned.



      select * from dual where not (1=2 and 5=null);


      Unexpectedly, row returned.



      Am I missing something basic how NOT works?
      Or how AND works?



      Tried in Oracle 11 and 12.







      sql oracle






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 22:07









      goo54321goo54321

      63




      63
























          1 Answer
          1






          active

          oldest

          votes


















          1














          This is all fine. Almost any operation with NULL returns NULL, including =, <>, and NOT.



          But, let's parse that last where:



          where not (1 = 2 and 5 = null);


          is the same as:



          where not (FALSE and NULL)


          Well, AND returns FALSE if any of the operands are FALSE -- even if others are NULL. Look at this another way, whether the NULL is "TRUE" or "FALSE", the expression is FALSE.



          Hence, the result is the same as:



          where TRUE





          share|improve this answer
























          • Thanks for the explanation. I guess my assumption was NULL and FALSE, would return NULL.

            – goo54321
            Nov 13 '18 at 22:23











          • @user2469062 . . . NULL OR FALSE returns NULL, but NULL AND FALSE is well-defined, because of the FALSE.

            – Gordon Linoff
            Nov 13 '18 at 22:34













          • I thought this was an interesting little topic so I made an SQLFiddle to show what's legitimate and what isn't. I thought others might find it informative.

            – Bob Jarvis
            Nov 13 '18 at 23:16











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290229%2fbasic-sql-logic-of-not-and-null-values-when-using%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          This is all fine. Almost any operation with NULL returns NULL, including =, <>, and NOT.



          But, let's parse that last where:



          where not (1 = 2 and 5 = null);


          is the same as:



          where not (FALSE and NULL)


          Well, AND returns FALSE if any of the operands are FALSE -- even if others are NULL. Look at this another way, whether the NULL is "TRUE" or "FALSE", the expression is FALSE.



          Hence, the result is the same as:



          where TRUE





          share|improve this answer
























          • Thanks for the explanation. I guess my assumption was NULL and FALSE, would return NULL.

            – goo54321
            Nov 13 '18 at 22:23











          • @user2469062 . . . NULL OR FALSE returns NULL, but NULL AND FALSE is well-defined, because of the FALSE.

            – Gordon Linoff
            Nov 13 '18 at 22:34













          • I thought this was an interesting little topic so I made an SQLFiddle to show what's legitimate and what isn't. I thought others might find it informative.

            – Bob Jarvis
            Nov 13 '18 at 23:16
















          1














          This is all fine. Almost any operation with NULL returns NULL, including =, <>, and NOT.



          But, let's parse that last where:



          where not (1 = 2 and 5 = null);


          is the same as:



          where not (FALSE and NULL)


          Well, AND returns FALSE if any of the operands are FALSE -- even if others are NULL. Look at this another way, whether the NULL is "TRUE" or "FALSE", the expression is FALSE.



          Hence, the result is the same as:



          where TRUE





          share|improve this answer
























          • Thanks for the explanation. I guess my assumption was NULL and FALSE, would return NULL.

            – goo54321
            Nov 13 '18 at 22:23











          • @user2469062 . . . NULL OR FALSE returns NULL, but NULL AND FALSE is well-defined, because of the FALSE.

            – Gordon Linoff
            Nov 13 '18 at 22:34













          • I thought this was an interesting little topic so I made an SQLFiddle to show what's legitimate and what isn't. I thought others might find it informative.

            – Bob Jarvis
            Nov 13 '18 at 23:16














          1












          1








          1







          This is all fine. Almost any operation with NULL returns NULL, including =, <>, and NOT.



          But, let's parse that last where:



          where not (1 = 2 and 5 = null);


          is the same as:



          where not (FALSE and NULL)


          Well, AND returns FALSE if any of the operands are FALSE -- even if others are NULL. Look at this another way, whether the NULL is "TRUE" or "FALSE", the expression is FALSE.



          Hence, the result is the same as:



          where TRUE





          share|improve this answer













          This is all fine. Almost any operation with NULL returns NULL, including =, <>, and NOT.



          But, let's parse that last where:



          where not (1 = 2 and 5 = null);


          is the same as:



          where not (FALSE and NULL)


          Well, AND returns FALSE if any of the operands are FALSE -- even if others are NULL. Look at this another way, whether the NULL is "TRUE" or "FALSE", the expression is FALSE.



          Hence, the result is the same as:



          where TRUE






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 22:10









          Gordon LinoffGordon Linoff

          766k35300402




          766k35300402













          • Thanks for the explanation. I guess my assumption was NULL and FALSE, would return NULL.

            – goo54321
            Nov 13 '18 at 22:23











          • @user2469062 . . . NULL OR FALSE returns NULL, but NULL AND FALSE is well-defined, because of the FALSE.

            – Gordon Linoff
            Nov 13 '18 at 22:34













          • I thought this was an interesting little topic so I made an SQLFiddle to show what's legitimate and what isn't. I thought others might find it informative.

            – Bob Jarvis
            Nov 13 '18 at 23:16



















          • Thanks for the explanation. I guess my assumption was NULL and FALSE, would return NULL.

            – goo54321
            Nov 13 '18 at 22:23











          • @user2469062 . . . NULL OR FALSE returns NULL, but NULL AND FALSE is well-defined, because of the FALSE.

            – Gordon Linoff
            Nov 13 '18 at 22:34













          • I thought this was an interesting little topic so I made an SQLFiddle to show what's legitimate and what isn't. I thought others might find it informative.

            – Bob Jarvis
            Nov 13 '18 at 23:16

















          Thanks for the explanation. I guess my assumption was NULL and FALSE, would return NULL.

          – goo54321
          Nov 13 '18 at 22:23





          Thanks for the explanation. I guess my assumption was NULL and FALSE, would return NULL.

          – goo54321
          Nov 13 '18 at 22:23













          @user2469062 . . . NULL OR FALSE returns NULL, but NULL AND FALSE is well-defined, because of the FALSE.

          – Gordon Linoff
          Nov 13 '18 at 22:34







          @user2469062 . . . NULL OR FALSE returns NULL, but NULL AND FALSE is well-defined, because of the FALSE.

          – Gordon Linoff
          Nov 13 '18 at 22:34















          I thought this was an interesting little topic so I made an SQLFiddle to show what's legitimate and what isn't. I thought others might find it informative.

          – Bob Jarvis
          Nov 13 '18 at 23:16





          I thought this was an interesting little topic so I made an SQLFiddle to show what's legitimate and what isn't. I thought others might find it informative.

          – Bob Jarvis
          Nov 13 '18 at 23:16


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290229%2fbasic-sql-logic-of-not-and-null-values-when-using%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly