Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does "delete from table where NULL = NULL" means?

What does delete from table where NULL = NULL mean?

like image 413
rociiu Avatar asked Jul 08 '10 06:07

rociiu


3 Answers

That will delete nothing from the table. NULL does not equal NULL.

Now

delete from table where NULL is NULL

would delete all rows from the table.

like image 70
Coxy Avatar answered Nov 09 '22 22:11

Coxy


It means don't delete anything, because NULL is never equal to anything. Or maybe it means "don't delete anything unless the user's DBMS really sucks, in which case delete it all out of spite".

Seriously though, that kind of construct usually comes about when a WHERE clause is procedurally generated -- rather than creating a special case for "do nothing", sometimes it's simpler just to generate a WHERE clause that causes the database to do nothing. I've usually seen "WHERE 0 = 1" though, which is less ambiguous.

like image 16
hobbs Avatar answered Nov 09 '22 22:11

hobbs


In SQL, there are three logical values, namely TRUE, FALSE, and UNKNOWN. when we compare null to null, using null=null, the operation will return UNKNOWN. Moreover,In the WHERE clause all UNKNOWN values are filtered out.Hence the query does nothing.

like image 8
Toan Nguyen Avatar answered Nov 09 '22 22:11

Toan Nguyen