title: MySQL get difference between two string fields
body: <p>All,
   I have a mySQL table with two fields, <code>old</code> and <code>new</code>. Each contain a string in the following format:</p>
  
  <p><code>key1=value1, key2=value2, key3=value3</code></p>
  
  <p>The keys used in each field for a row are the same, the values may change. For each row, the keys may differ.</p>
  
  <p>Is it possible to have two further columns which compare the values in <code>old</code> and <code>new</code> and only outputs those key/value pairs which differ?</p>
  
  <pre><code>old                          | new                          | diff_old          | diff_new
  key1=xxx, key2=yyy, key3=zzz | key1=xxx, key2=aaa, key3=zzz | key2=yyy          | key2=aaa
  keya=xxx, keyb=yyy, keyc=zzz | keya=111, keyb=yyy, keyc=222 | keya=xxx, keyc=zzz| keya=111, keyc=222
  </code></pre>
  
  <p>Im aware <code>SUBSTRING_INDEX</code> can be used to split strings, however the issue is the differing key/value pairs between rows, meaning a function cant be cooked in so easily.</p>