dbTalk Databases Forums  

weird results: (null!=null)??

comp.databases.mysql comp.databases.mysql


Discuss weird results: (null!=null)?? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
alex
 
Posts: n/a

Default weird results: (null!=null)?? - 09-26-2006 , 05:11 AM






I've got this select:

select * from table1,table2 where table1.field1=table2.field1 and
table1.field2=table2.field2

and it does not return any rows for the elements where both "field2" are
null.

the only way i can get those rows is using this query:

select * from table1,table2 where table1.field1=table2.field1 and
table1.field2=table2.field2 or (table1.field2 is null and table2.field2
is null)


is this the normal behaviour? is there any other way in which those rows
where both fields are null are returned?

alex.

Reply With Quote
  #2  
Old   
alex
 
Posts: n/a

Default Re: weird results: (null!=null)?? - 09-26-2006 , 05:27 AM






En/na alex ha escrit:
Quote:
select * from table1,table2 where table1.field1=table2.field1 and
table1.field2=table2.field2 or (table1.field2 is null and table2.field2
is null)
ok, it seems this is a generic sql feature. so i'm going to use the "or"
query. btw, the query was wrong as it needed a pair or parenthesis more:

select * from table1,table2 where table1.field1=table2.field1 and
(table1.field2=table2.field2 or (table1.field2 is null and table2.field2
is null))


Reply With Quote
  #3  
Old   
PleegWat
 
Posts: n/a

Default Re: weird results: (null!=null)?? - 09-26-2006 , 05:58 AM



In article <4518fcd9$0$75040$14726298 (AT) news (DOT) sunsite.dk>, alex says...
Quote:
is this the normal behaviour? is there any other way in which those rows
where both fields are null are returned?
In all of the various programming languages I've used so far that have
null, it is valid that (null != null)

--
PleegWat
Remove caps to reply


Reply With Quote
  #4  
Old   
Murdoc
 
Posts: n/a

Default Re: weird results: (null!=null)?? - 09-26-2006 , 06:12 AM



PleegWat wrote:

Quote:
In article <4518fcd9$0$75040$14726298 (AT) news (DOT) sunsite.dk>, alex says...
is this the normal behaviour? is there any other way in which those rows
where both fields are null are returned?

In all of the various programming languages I've used so far that have
null, it is valid that (null != null)
That's not exactly correct. In Java, for example, the comparison (null == null) equates to true. This applies to Progress also.

I haven't tested any other languages, as these were the two that I have available.

--



Reply With Quote
  #5  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: weird results: (null!=null)?? - 09-26-2006 , 07:56 AM



Murdoc wrote:
Quote:
PleegWat wrote:


In article <4518fcd9$0$75040$14726298 (AT) news (DOT) sunsite.dk>, alex says...

is this the normal behaviour? is there any other way in which those rows
where both fields are null are returned?

In all of the various programming languages I've used so far that have
null, it is valid that (null != null)


That's not exactly correct. In Java, for example, the comparison (null == null) equates to true. This applies to Progress also.

I haven't tested any other languages, as these were the two that I have available.

C/C++ it's also true, but that's because null is actually just a special
value (usually 0, but not necessarily). However, SQL defines any
comparison to NULL as false.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================


Reply With Quote
  #6  
Old   
Meghana Chitale
 
Posts: n/a

Default Re: weird results: (null!=null)?? - 09-26-2006 , 09:00 AM



In SQL null is not a value, but it means actual value is not known for
that column. Hence one unknown value can not be compared with other
unknown value to say weather they are equal or not.So if you want to
join on columns that can be null you have to take special care of using
syntax like 'column is null' as you have done in the query below.

alex wrote:
Quote:
En/na alex ha escrit:

select * from table1,table2 where table1.field1=table2.field1 and
table1.field2=table2.field2 or (table1.field2 is null and
table2.field2 is null)

ok, it seems this is a generic sql feature. so i'm going to use the "or"
query. btw, the query was wrong as it needed a pair or parenthesis more:

select * from table1,table2 where table1.field1=table2.field1 and
(table1.field2=table2.field2 or (table1.field2 is null and table2.field2
is null))

Reply With Quote
  #7  
Old   
Murdoc
 
Posts: n/a

Default Re: weird results: (null!=null)?? - 09-28-2006 , 02:33 AM



Jerry Stuckle wrote:

Quote:
Murdoc wrote:
PleegWat wrote:


In article <4518fcd9$0$75040$14726298 (AT) news (DOT) sunsite.dk>, alex says...

is this the normal behaviour? is there any other way in which those rows where both fields are null are returned?

In all of the various programming languages I've used so far that have null, it is valid that (null != null)


That's not exactly correct. In Java, for example, the comparison (null == null) equates to true. This applies to Progress also.

I haven't tested any other languages, as these were the two that I have available.


C/C++ it's also true, but that's because null is actually just a special value (usually 0, but not necessarily). However, SQL defines any comparison to NULL as false.
That's interesting. Progress does a similar thing, that any arithmetic or boolean operation with a ? value returns ?, except for something like (? eq ?).

--



Reply With Quote
Reply




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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.