title: How do I write a loop in MySQL for each value in a comma separated string?
body: <p>I have a value (IP Address) in TableA.   If this value does not exist in the comma separated value field in TableB I need to delete the row in TableA.  I can retrieve these IP's with the following but I have to repeat for each entry in the CSV String.  The number of values in TableB's CSV String column can fluctuate. My Stringsplit function is a simple Parsing (Substr()) of the string the comma and position are the parameters.  The last parameter needs to increase each pass until done  </p>
  
  <pre><code>*SELECT * FROM TableA AS A
  JOIN `TableB` AS B ON B.ID = A.ID
  WHERE 
  A.`column` &lt;&gt; stringsplit(B.`Column`,',',1) AND
  A.`column` &lt;&gt; stringsplit(B.`Column``,',',2) AND
  A.`column` &lt;&gt; stringsplit(B.`Column`,',',3) AND
   ETC......
  </code></pre>
  
  <p>I can obtain an accurate count of these values by:</p>
  
  <pre><code>SELECT CASE WHEN TableB.Column = '' THEN 0 ELSE (LENGTH(TableB.Column`) - LENGTH(REPLACE(TableB Column, ',', ''))+1) END AS value_count
    FROM `TableB`*
  </code></pre>
  
  <p>How can this be done dynamically adjusting the parameter in the Stringsplit() to increase with each pass?</p>