Considering the data-table as below:
tags |
---|
alpha |
alpha, beta |
delta |
beta, gamma |
How can get all different tags in one query? So the expected result should be:
alpha
beta
gamma
delta
(order is not important)
I have been thinking a lot, but could not find out the solution. 🙂
2
Answers
Assuming that there would be a max of 3 CSV words per record and that you are using MySQL 8+, we can try using a regex substring approach:
We get all tags splited by ‘,’ then we use
union
to keeps unique records only :