I have two tables
Table1 with list of users comma separated
Name UserID
abc A,B,C,D
def A,B,C
Table2
Name UserID
abc A
abc B
abc C
def A
def B
I need to find the users that are in table1 for each Name but not in table2 (There won’t ever be an instance when a UserID to Name pair is present in table2 but not in table1 as CSV).
The output should be
Name UserID
abc D
def C
I can do this with PHP but is there a way this can be done through a query? I am not sure where to begin in case I’m doing this as a query. Can I parse in MySQL using comma as delimiter?
I plugged your test data into a test schema in SQLFiddle and ran the query that follows.
Here’s the link to SQLFiddle with the test and positive results:
http://sqlfiddle.com/#!2/83dfd/4/0
Here’s the query:
If you have very long column width in table1 you might need to expand the “INDEX_TABLE” subquery. You can copy and paste over it with the code at this link to do so:
http://www.experts-exchange.com/Database/MySQL/A_3573-A-MySQL-Tidbit-Quick-Numbers-Table-Generation.html