I’m trying to do this query which updates only the first column that is empty. Here is a query so far:
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
It updates all of columns with ‘Jimmy’. I think that that’s because the SET will update it then move on to the next SET and will update that etc…Am I right on what’s causing this? If so how could I fix this? If not how should I rewrite this?
I think if you swap the order, it will work properly.
Try this: