• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

null = null is false :confused:

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why is null = null is false and null <> null is also false?
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
null means it is not pointing to no object. null == null , means it gives false ,beacause both are not pointing to same object, even objects are not ther while comparing.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI

null==null prints true, because eventhough '==' comparator compares two object references rather tha content, here there is no object as such.So it will print True.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sridhar Padala:
null==null prints true...



I assume we're discussing null=null in an SQL context, not Java.
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quote from Head First SQL


Head First: Calm down and let me get this
straight. You aren�t equal to zero, you aren�t an
empty string variable. And you aren�t even equal to
yourself ? That makes no sense!

NULL: I know it�s confusing. Just think of me
this way: I�m undefined. I�m like the inside of an
unopened box. Anything could be in there, so you
can�t compare one unopened box to another because
you don�t know what�s going to be inside of each
one. I might even be empty. You just don�t know.


You should take a look at Head First SQL. As anything could be there, so null == null returns false, the same with null <> null.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really understood the concept of null from the Head First SQL. A database null is like a closed box and you never know what's going to be inside in the future and you cannot compare a closed box with another closed box.
 
author
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quote, Jothi. That's what we try to do throughout these books, explain with metaphors and illustrations to make what seems to be confusing very clear.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jothi Shankar Kumar Sankararaj:
I really understood the concept of null from the Head First SQL. A database null is like a closed box and you never know what's going to be inside in the future and you cannot compare a closed box with another closed box.



thanks jothi and Louis for sharing this, yes it looks much easier to understand the concept. :thumb:
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lynn,

That was an amazing piece of example to really understand what null is in a database.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But nobody has told him what you ought to write.

If I remember correctly, null in Java means something which doesn't exist, and null in SQL means more like the English "don't know." A bit like RM Reddy's birthday. I don't know when it is, so if I were to put RM Reddy into a database with a BIRTHDAY column, I would have to put null in it. Now I would also put null if I entered Shankar Reddy Telukutla's birthday. Remember this is SQL not Java.
Now both values are recorded as null, but if you ask "do these people have the same birthday?" the answer is "don't know" which SQL expresses as null.

I think there is a standard SQL operator something like is-null, but you will have to go through an SQL tutorial like this one (go to Data statements then Where then look for null) and find out what it says there.

BTW: In Java (null == null) returns true.
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie:
But nobody has told him what you ought to write.

If I remember correctly, null in Java means something which doesn't exist, and null in SQL means more like the English "don't know." A bit like RM Reddy's birthday. I don't know when it is, so if I were to put RM Reddy into a database with a BIRTHDAY column, I would have to put null in it. Now I would also put null if I entered Shankar Reddy Telukutla's birthday. Remember this is SQL not Java.
Now both values are recorded as null, but if you ask "do these people have the same birthday?" the answer is "don't know" which SQL expresses as null.

I think there is a standard SQL operator something like is-null, but you will have to go through an SQL tutorial like this one (go to Data statements then Where then look for null) and find out what it says there.

BTW: In Java (null == null) returns true.



In SQL

NULL = NULL is false
NULL != NULL is false.

It is not comparative.

The SQL operator you're thinking of for testing for Null is "IS NULL" and "IS NOT NULL". You can also use the COALESCE function to convert a null column to something comparative: COALESCE(column,substitutionValue)

0 = COALESCE(columnOfZeros, 0) is True

I skimmed through Lynn's book in Safari's online books... I wouldn't hesitate in suggesting it to someone wanting to learn SQL. It seems very complete and a really good start to building your knowledge in the subject.
[ October 19, 2007: Message edited by: Paul Campbell ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic