title: MySQL: UPDATE ... ON DUPLICATE KEY "ANOTHER UPDATE"?
body: <p>I've stumbled on a problem which is supposedly should have a valid solution in a single MySQL query, yet I can't figure it out (I'm far from an expert in MySQL, alas).</p>
  
  <p>The table has the following columns: A, B, C. (A, B) is a primary key (INTs). C - is a string. The table is populated with records.</p>
  
  <p>Under some conditions I need to update a value <code>x</code> in column A to new value <code>y</code>. If some records do already have <code>y</code> in A (can be many at once, for records with different values in B), "duplicate key(s)" condition occurs. In such case, I need to concatenate values in C from old records and corresponding pending updates, for every specific <code>b</code>.</p>
  
  <p>Example:</p>
  
  <pre>
  |  A  |  B  |   C
  |  1  |  2  |  ABC
  |  1  |  4  |  DEF
  |  2  |  2  |  GHI
  |  2  |  4  |  JKL
  |  2  |  5  |  MNO
  </pre>
  
  <p>After update in A as 2 -> 1, I need to get:</p>
  
  <pre>
  |  A  |  B  |   C
  |  1  |  2  |  ABCGHI
  |  1  |  4  |  DEFJKL
  |  1  |  5  |  MNO
  </pre>
  
  <p>There is a well-known <code>INSERT ... ON DUPLICATE KEY UPDATE</code> statement. But how to handle gracefully the same problem on updates? I'm not sure if and how <code>REPLACE</code> statement or <code>REPLACE</code> function can be used for the task.</p>
  
  <p>Thanks in advance.</p>