For some reason, the request does not want to work:

UPDATE table SET field1 = IF(field2 = 0, 1, field1) WHERE id = ' . $id; 

Did I build it right? It is necessary, depending on the value of the field, to write another value in it or leave it as before.

    3 answers 3

    Maybe so?

     UPDATE table SET field1 = CASE WHEN field2 = 0 THEN 1 ELSE field1 END 
       SELECT CASE <variable> WHEN <value> THEN <returnvalue> WHEN <othervalue> THEN <returnthis> ELSE <returndefaultcase> END FROM <table> 

      Adjust for yourself.

      • one
        Same Select and need Update - Saidolim
      • one
        I put the author in the right direction, he will write the code himself. - mix

      It seems to me that the request simply lacks one little letter:

       UPDATE table SET field1 = IIF(field2 = 0, 1, field1) WHERE id = ' . $id; 

      IIF function