title: Split a MYSQL string from GROUP_CONCAT into an ( array, like, expression, list) that IN () can understand
body: <p>This question follows on from <a href="https://stackoverflow.com/questions/4649107/mysql-join-results-set-wiped-results-during-in-in-where-clause">MYSQL join results set wiped results during IN () in where clause?</a></p>
  
  <p>So, short version of the question. How do you turn the string returned by GROUP_CONCAT into a comma-seperated expression list that IN() will treat as a list of multiple items to loop over? </p>
  
  <p>N.B. The MySQL docs appear to refer to the "( comma, seperated, lists )" used by IN () as 'expression lists', and interestingly the pages on IN() seem to be more or less the only pages in the MySQL docs to ever refer to expression lists. So I'm not sure if functions intended for making arrays or temp tables would be any use here. </p>
  
  <hr>
  
  <p>Long example-based version of the question: From a 2-table DB like this:</p>
  
  <pre><code>SELECT id, name, GROUP_CONCAT(tag_id) FROM person INNER JOIN tag ON person.id = tag.person_id GROUP BY person.id;
  +----+------+----------------------+
  | id | name | GROUP_CONCAT(tag_id) |
  +----+------+----------------------+
  |  1 | Bob  | 1,2                  |
  |  2 | Jill | 2,3                  |
  +----+------+----------------------+
  </code></pre>
  
  <p>How can I turn this, which since it uses a string is treated as logical equivalent of ( 1 = X ) AND ( 2 = X )...</p>
  
  <pre><code>SELECT name, GROUP_CONCAT(tag.tag_id) FROM person LEFT JOIN tag ON person.id = tag.person_id 
  GROUP BY person.id HAVING ( ( 1 IN (GROUP_CONCAT(tag.tag_id) ) ) AND ( 2 IN (GROUP_CONCAT(tag.tag_id) ) ) );
  Empty set (0.01 sec)
  </code></pre>
  
  <p>...into something where the GROUP_CONCAT result is treated as a list, so that for Bob, it would be equivalent to:</p>
  
  <pre><code>SELECT name, GROUP_CONCAT(tag.tag_id) FROM person INNER JOIN tag ON person.id = tag.person_id AND person.id = 1 
  GROUP BY person.id HAVING ( ( 1 IN (1,2) ) AND ( 2 IN (1,2) ) );
  +------+--------------------------+
  | name | GROUP_CONCAT(tag.tag_id) |
  +------+--------------------------+
  | Bob  | 1,2                      |
  +------+--------------------------+
  1 row in set (0.00 sec)
  </code></pre>
  
  <p>...and for Jill, it would be equivalent to:</p>
  
  <pre><code>SELECT name, GROUP_CONCAT(tag.tag_id) FROM person INNER JOIN tag ON person.id = tag.person_id AND person.id = 2 
  GROUP BY person.id HAVING ( ( 1 IN (2,3) ) AND ( 2 IN (2,3) ) );
  Empty set (0.00 sec)
  </code></pre>
  
  <p>...so the overall result would be an exclusive search clause requiring all listed tags that doesn't use HAVING COUNT(DISTINCT ... ) ?</p>
  
  <p>(note: This logic works without the AND, applying to the first character of the string. e.g. </p>
  
  <pre><code>SELECT name, GROUP_CONCAT(tag.tag_id) FROM person LEFT JOIN tag ON person.id = tag.person_id 
    GROUP BY person.id HAVING ( ( 2 IN (GROUP_CONCAT(tag.tag_id) ) ) );
  +------+--------------------------+
  | name | GROUP_CONCAT(tag.tag_id) |
  +------+--------------------------+
  | Jill | 2,3                      |
  +------+--------------------------+
  1 row in set (0.00 sec)
  </code></pre>