What is the difference between the following 2 queries?
DELETE FROM experience WHERE end IS NOT NULL;
And
DELETE FROM experience WHERE NOT( end=NULL);
First query was accepted as a correct answer but second was not.
The IS NULL condition is satisfied if the column contains a null value or if the expression cannot be evaluated because it contains one or more null values. If you use the IS NOT NULL operator, the condition is satisfied when the operand is column value that is not null, or an expression that does not evaluate to null.
The IS NOT NULL condition is used in SQL to test for a non-NULL value. It returns TRUE if a non-NULL value is found, otherwise it returns FALSE. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
The NOT NULL constraint is used to ensure that a given column of a table is never assigned the null value. Once a NOT NULL constraint has been defined for a particular column, any insert or update operation that attempts to place a null value in that column will fail.
In MySQL, 0 or NULL means false and anything else means true.
NULLs are a bit weird. A NULL is never equal to anything including another NULL. Further, any boolean operation against a NULL returns NULL.
The expression end IS NOT NULL
will evaluate false
if end
is NULL, and true
if end
is not NULL.
The expression NOT( end=NULL)
will actually always evaluate to NULL because (end = NULL)
equals NULL and NOT (NULL)
also equals NULL. More to the point in a WHERE clause, it will never evaluate true
.
NULL values are treated differently from other values.
NULL is used as a placeholder for unknown or inapplicable values. It is not possible to test for NULL values with comparison operators, such as =, <, or <>
You will have to use the IS NULL and IS NOT NULL operators instead.
Please refer below link for more details.
http://www.w3schools.com/sql/sql_null_values.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With