I’m trying to figure out why I’m not getting a result from a MySQL Query I’m running.
I’m trying to replace a NULL value with a number with in a query, but I can’t figure out what I’m doing wrong.
Here’s my query:
UPDATE Details
SET HowHear_ID = CASE HowHear_ID
WHEN '' THEN 25
WHEN NULL THEN 25
WHEN 7 THEN 25
WHEN 8 THEN 5
WHEN 16 THEN 25
WHEN 17 THEN 16
END
WHERE HowHear_ID IN ('',NULL,7,8,16,17)
This Query will effect all but the NULL values.
What am I doing wrong??
No value will ever equal (or “unequal”)
NULLin SQL. Understand the following truth table:Since the following are equivalent…
… you cannot put
NULLon the right hand side of anIN predicate. Interestingly, things get even worse when you putNULLon the right hand side of aNOT IN predicate:If
bwereNULL, the whole expression will becomeNULL(or maybeFALSE), but neverTRUE. This is also the case forNOT IN (subselect)predicates! So, never do this:The correct solution in your case uses a
NULL predicateinstead. Do this:Or this: