title: mysql update multiple column one row single statement vs multiple statements
body: <p>I am trying to update 3 column values in a row in mysql only if any of the 3 values is different.</p>
  
  <p>Say  I have a table of </p>
  
  <p><strong>x,y,z,id columns</strong></p>
  
  <p>I have currently, </p>
  
  <p>Method A</p>
  
  <pre><code>update foo set x = 'x_value', y = 'y_value', z = 'z_value' where id = 'unique_id'
  and ((x &lt;&gt; 'x_value') or (y &lt;&gt; 'y_value') or (z &lt;&gt; 'z_value'))
  </code></pre>
  
  <p>I don't know much about the theoretical benchmarking/architecture of mysql, and I was wondering if the statements</p>
  
  <p>Method B</p>
  
  <pre><code>update foo set x ='x_value' where id = 'unique_id' and ((x &lt;&gt; 'x_value')); 
  update foo set y ='y_value' where id = 'unique_id' and ((y &lt;&gt; 'y_value')); 
  update foo set z ='z_value' where id = 'unique_id' and ((z &lt;&gt; 'z_value')); 
  </code></pre>
  
  <p>is better or superior.</p>
  
  <p>I realize that Method B will only do one write and 3 reads if only one column has changed, vs 3 writes and 3 reads for the Method A. I just don't know if it is more time intensive because method B requires looking up the index row 3 times.</p>
  
  <p>Thanks in advance!</p>