title: Conditional UPDATE in MySQL
body: <p>I am trying to <code>UPDATE</code> values from a table, but I need to add some conditions. I found the function <code>CASE</code>, but I am not if it is the best method.</p>
  <p>Here is an example. My table is 'relation':</p>
  <pre>
  userid1 | userid2 | name1 | name2
  </pre>
  <p>I got for example:</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT * 
  FROM relation 
  WHERE (userid1 = 3 AND userid2 = 4)
        OR (userid1 = 4 AND userid2 = 3);  
  </code></pre>
  <p>Output:</p>
  <pre>
  4 | 3 | bill | jack
  </pre>
  <p>and I want to change the name of the user 3 in the relation between 3 and 4, but I don't know if it is the <code>userid1</code> or the <code>userid2</code>.</p>
  <p>I thought of case:</p>
  <pre class="lang-sql prettyprint-override"><code>UPDATE relation 
     CASE WHEN userid1 = 3 THEN SET name1 = 'jack' END 
          WHEN userid2 = 3 THEN SET name2 = 'jack' END 
  WHERE (userid1 = 3 AND userid2 = 4) 
        OR (userid1 = 4 AND userid2 = 3);
  </code></pre>
  <p>But it doesn't work! Any ideas?</p>
  <p>Thanks very much in advance.</p>