I'm not 100% clear on what you are looking to output. I think you are saying that you want to return the values from the value
column that occur more than once in any row in your comma-separated list.
In that case, the following query will produce the output you want:
SELECT result
FROM (
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(value, ',', a.letter + 1), ',', -1) result
FROM t1
INNER JOIN (SELECT 0 letter UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) a ON LENGTH(REPLACE(value, ',' , '')) <= LENGTH(value) - a.letter
) a
GROUP BY result
HAVING COUNT(result) > 1
ORDER BY result
OUTPUT:
result
A
B
C
E
F
G
Why these results? Each of these letters occurs at least twice in the comma-separated lists. For example, A
occurs twice (in row 1 and row 4), E
occurs three times (in rows 2, 3, and 4), etc.
Note: This currently supports comma-separated lists of up to 4 letters only. It's not clear from your sample data whether this is enough or not.
Edit following OP comment
To get a list of all of the letters, change to use this SQL:
SELECT result
FROM (
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(value, ',', a.letter + 1), ',', -1) result
FROM t1
INNER JOIN (SELECT 0 letter UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) a ON LENGTH(REPLACE(value, ',' , '')) <= LENGTH(value) - a.letter
) a
GROUP BY result
ORDER BY result
Removing the HAVING COUNT(result) > 1
will cause all results to be returned.