![]() |
difference between 'is null' and '= null'
Both works, with different result. What is the logic ?
|
You'll want to use IS NULL. = NULL is an arithmetic operator that can have some odd results:
http://dev.mysql.com/doc/refman/5.0/...with-null.html |
Yes, I was convinced, until special case query(where I got a bit confused (-:) that '= null' does not exists at all.
But see this dilema: tab1 Code:
id Code:
id varcharfiieldselect * from tab2 where varcharfield = null' and in this case: select * from tab1 left join tab2 on tab1.id = tab2.id were tab1.id is null coz, in first case null is actualy there, in table, in second it is not, it is produced by query. Do you mean 'is null' should work in any upper case & in any case at all ? |
In databases NULL means the value is unknown and therefore NULL == NULL is false since two unknowns are rarely going to be the same value if you ever find out what they are. So testing for = NULL will never find a match as NULL is never equal to anything.
Once you move out of the database null has a completely different meaning and two fields set to null are equal. The NULL in the database doesn't extract as a meaningful value though because outside the database there is no corresponding value meaning unknown to give the field. |
Quote:
That may be true in PHP and JavaScript, but it is *NOT* true in some computer languages. This is a table of the comparison operators from VBScript, just for example: http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx VB and VB.NET are essentially the same: They use the "IS" operator for testing object equality, and two nulls will not match using anything except the IS operator. Pascal, in most variations I've seen, is the same. Only languages that don't seem to have a built in "isNull" or equivalent function/operator seem to treat a pair of nulls as being equal. It *IS* misleading to say that a pair of nulls are equal, for the reason Felgall gave: NULL means "unknown" and how can you know that a pair of unknowns are equal. I think this is a case where VB/VB.NET/VBScript do it better than JavaScript, C, C++, et al. If nothing else, how does it make sense to ask Code:
if ( a <= null ) |
Quote:
Quote:
In JavaScript (null === 0) will return false because it does not treat them the same unless you are sloppy and use == which first tries to convert both values to the same type and both null and 0 can be converted to false giving false == false which is true.. |
YES! I think I wish that JS disallowed using null with == and !=. I certainly admit to sloppily using them way too often.
I *REALLY* dislike code that does stuff such as Code:
if ( ! document.getElementsByClassName ) { ... }Code:
if ( document.getElementsByClassName === null ) { ... } |
Quote:
The correct way to write it is: Code:
if (typeof document.getElementsByClassName === undefined ) { ... } |
SORRY! Senior moment. I knew that.
|
| All times are GMT +1. The time now is 11:39 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.