Francesco G. Francesco G. - 1 year ago 75
MySQL Question

Mysql UPDATE IF FIELD IS EMPTY SET VALUE ELSE CONCAT VALUE

I've a syntax error in my query:

UPDATE users SET name=IF(name='', 'mario', CONCAT(name, ',mario') WHERE id=1


Somebody can help me?

Answer Source

You missed a closing bracket after CONCAT().

Your fixed query looks like this:

UPDATE users SET name=IF(name='', 'mario', CONCAT(name, ',mario')) WHERE id=1