title: MySql Update with count based on an input of comma separated values
body: <p>If I were to supply MySql a comma separated string like ('US,UK,CA') (which comes from a form through a php script), how can I get MySql to loop through that string and do a count for each country code in there and update a different table where the country codes in that table are equal to the country codes in the string.</p>
  
  <p>Example:</p>
  
  <p><strong>table_a</strong></p>
  
  <pre><code>"id"    "countries"
  "1"     "US,CA"
  "2"     "US,CA"
  "3"     "US,AU"
  "4"     "US,UK"
  "5"     "US"
  </code></pre>
  
  <p><strong>table_b</strong></p>
  
  <pre><code>"id"    "country"   "total"
  "1"     "US"        "0"
  "2"     "CA"        "0"
  "3"     "UK"        "0"
  "4"     "AU"        "0"
  </code></pre>
  
  <p>How can I do:</p>
  
  <p><strong>Eg: if I supplied ('US,UK,CA')</strong></p>
  
  <pre><code>update table_b set country = (
  
      select count(id) from table_a where country = (// each country in that string ('US,UK,CA'))
  
  ) where country = (country currently selected from the string above)
  </code></pre>
  
  <p>Can something like this be done? It works OK if there's just one country. How can I do it when there are more?</p>
  
  <p>In the end, I'm hoping to end up with results like:</p>
  
  <pre><code>table_b
  "id"    "country"   "total"
  "1"     "US"        "5" // There are 5 in table_a
  "2"     "CA"        "2" // There are 2 in table_a
  "3"     "UK"        "1" // Only 1 in table_a
  "4"     "AU"        "1" // Only 1 in table_a
  </code></pre>