Bug #12 CASE ... ; and NULLs
Submitted: 11 Dec 2002 17:42 Modified: 26 Nov 2003 12:14
Reporter: Alexander Keremidarski Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:3.23.53 OS:Any (any)
Assigned to: CPU Architecture:Any

[11 Dec 2002 17:42] Alexander Keremidarski
Description:
When CASE ... WHEN ... END; is used and under some condition it evaluates as NULL all consequent values also become NULL if result is used in 
GROUP BY
INSERT ... SELECT
CREATE ... SELECT

while result is Ok otherwise

How to repeat:
create table a (b int); 
insert into a values (1), (2), (3); 

select b, case b when 2 then NULL else b end as c from a;
+------+------+
| b    | c    |
+------+------+
|    1 | 1    |
|    2 | NULL |
|    3 | 3    |
+------+------+

Now the BUG:

mysql> select b, case b when 2 then NULL else b end as c from a group by b;
+------+------+
| b    | c    |
+------+------+
|    1 | 1    |
|    2 | NULL |
|    3 | NULL |
+------+------+


create table d select b, case b when 2 then NULL else b end as c from a;
select * from d;
+------+------+
| b    | c    |
+------+------+
|    1 | 1    |
|    2 | NULL |
|    3 | NULL |
+------+------+

insert into d select b, case b when 2 then NULL else b end as c from a;
select * from d;
+------+------+
| b    | c    |
+------+------+
|    1 | 1    |
|    2 | NULL |
|    3 | NULL |
|    1 | 1    |
|    2 | NULL |
|    3 | NULL |
+------+------+

I simplified original report which contained:
SELECT ... MAX(CASE ...) ... GROUP BY ...;
result was wrong because as above shows that after frst NULL CASE evaluates as NULL so
 MAX(List_of_NULLs)  -> NULL
[27 Dec 2002 20:45] MySQL Developer
Fixed in 3.23.55