title: UPDATE multiple rows with different values in one query in MySQL
body: <p>I am trying to understand how to UPDATE multiple rows with different values and I just don't get it. The solution is everywhere but to me it looks difficult to understand.</p>
  <p>For instance, three updates into 1 query:</p>
  <pre><code>UPDATE table_users
  SET cod_user = '622057'
      , date = '12082014'
  WHERE user_rol = 'student'
      AND cod_office = '17389551'; 
  
  UPDATE table_users
  SET cod_user = '2913659'
      , date = '12082014'
  WHERE user_rol = 'assistant'
      AND cod_office = '17389551'; 
  
  UPDATE table_users
  SET cod_user = '6160230'
      , date = '12082014'
  WHERE user_rol = 'admin'
      AND cod_office = '17389551'; 
  </code></pre>
  <p>I <a href="https://web.archive.org/web/20161027063005/http://www.karlrixon.co.uk/writing/update-multiple-rows-with-different-values-and-a-single-sql-query/" rel="nofollow noreferrer">read</a> an example, but I really don't understand how to make the query. i.e:</p>
  <pre><code>UPDATE table_to_update
  SET cod_user= IF(cod_office = '17389551','622057','2913659','6160230')
      ,date = IF(cod_office = '17389551','12082014')
  WHERE ?? IN (??) ;
  </code></pre>
  <p>I'm not entirely clear how to do the query if there are multiple condition in the WHERE and in the IF condition..any ideas?</p>