title: NodeJS MySQL Update If Null
body: <p>I'm using MySQL with NodeJS and I'm just pretty new.</p>
  <p>I want to UPDATE col value if it's null else UPDATE for another col.</p>
  <p>Simply like that: If col1 is null UPDATE else UPDATE col2.</p>
  <pre><code>    app.post('/api/update', (req, res) =&gt; {
          const convidn = req.body.conversationid
          const currentuser = req.body.current
       
      
         var sql = &quot;UPDATE messages SET whodeleted='&quot;+currentuser+&quot;' WHERE converid = '&quot; + convidn + &quot;'&quot;;
  </code></pre>
  <p>That overwrites column value. I just want to if &quot;whodeleted&quot; is not null UPDATE for &quot;whodeleted2&quot; colum.</p>
  <pre><code>        db.query(sql, (err, result) =&gt; {
              if (err) throw err;
              console.log(&quot;Number of records deleted: &quot; + result.affectedRows);
          });
      })
  </code></pre>