Search code examples
mysqlsql-updateisnull

mysql update value if another one is not null


what's wrong with this query?

UPDATE `order` SET `total_no_vat` = IF(`total` IS NULL,NULL,(`total`/(1.10)));

I get an error that I cannot interpret:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') )' at line 1

any clue?


Solution

  • You can simply do:

    UPDATE `order` SET `total_no_vat` = `total`/(1.10);
    

    If total is NULL then total/(1.10) evaluates to NULL.