Mysql CASE and UPDATE
- by Rosengusta Garrett
I asked yesterday how I could update only the first column that was empty. I got this of a answer:
UPDATE `names` SET
`name_1` = CASE WHEN `name_1` = '' then 'Jimmy' else `name_1` end,
`name_2` = CASE WHEN `name_1` != '' and `name_2` = '' then 'Jimmy' else `name_2` end
I tried it and it ended up updating every column with 'Jimmy' what's wrong with this? I can't find anything. It could possibly be the structure of the database. So here is what each name_* column is setup like:
# Name Type Collation Attributes Null Default Extra
1 name_1 varchar(255) latin1_swedish_ci No None