If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > What the result if two columns are compared and both of them are nulls?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-22-04, 16:04
hiolgc hiolgc is offline
Registered User
 
Join Date: Mar 2004
Posts: 61
Talking What the result if two columns are compared and both of them are nulls?

Hi everyone,

What the result from the below query if there is record which CONTACT_ID=10 and USER_ID column is null? Nothing is found or the record is shown?

select * from CONTACT where CONTACT_ID=10 and USER_ID=USER_ID

Thanks,
Reply With Quote
  #2 (permalink)  
Old 04-22-04, 16:09
Tank Tank is offline
Registered User
 
Join Date: Feb 2004
Location: Copenhagen
Posts: 220
IS NULL ??

I shall assume you mean:

select * from CONTACT where CONTACT_ID=10 and USER_ID IS NULL

And yes then the record is shown

(the syntax is not =NULL, but IS NULL)

BOW
__________________
Kristian K. Hansen
Project Supervisor
National Board of Health
Reply With Quote
  #3 (permalink)  
Old 04-22-04, 16:19
hiolgc hiolgc is offline
Registered User
 
Join Date: Mar 2004
Posts: 61
Re: IS NULL ??

No, I know that. I mean How DB2 compares two columns if they are both null.

Thanks,

Quote:
Originally posted by Tank
I shall assume you mean:

select * from CONTACT where CONTACT_ID=10 and USER_ID IS NULL

And yes then the record is shown

(the syntax is not =NULL, but IS NULL)

BOW
Reply With Quote
  #4 (permalink)  
Old 04-22-04, 16:33
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: IS NULL ??

AFAIK, two null values are not equal ...

As an example ,

$ db2 "select * from sysibm.sysdummy1 where (cast(null as integer)=cast(null as integer))"

IBMREQD
-------

0 record(s) selected.

but

$ db2 "select * from sysibm.sysdummy1 where (cast('2' as integer)=cast('2' as integer))"

IBMREQD
-------
Y

1 record(s) selected.

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #5 (permalink)  
Old 04-22-04, 16:41
hiolgc hiolgc is offline
Registered User
 
Join Date: Mar 2004
Posts: 61
Re: IS NULL ??

You are right. Two null columns are not equal. Even the two columns are the same one. That's very prone to error because for most of us (even Datastage server) they are equal if both sides of = are null.

Thanks,

Quote:
Originally posted by sathyaram_s
AFAIK, two null values are not equal ...

As an example ,

$ db2 "select * from sysibm.sysdummy1 where (cast(null as integer)=cast(null as integer))"

IBMREQD
-------

0 record(s) selected.

but

$ db2 "select * from sysibm.sysdummy1 where (cast('2' as integer)=cast('2' as integer))"

IBMREQD
-------
Y

1 record(s) selected.

HTH

Sathyaram
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On