Francesco G. Francesco G. - 3 months ago 10
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

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