Substrings in a loop separated by a comma in a record

Consider the entry DOMAIN={domain1,domain2,domain3} , how can I check if domain1 or domain2 or domain3 is in the list?

For example: list={domain5, domain 2, domain6}

 ------------------------------------ | CONTEXT | DOMAIN | -----------------------------------| | context1 |domain1,domain2,domain3| |----------------------------------| 

I tried SELECT * FROM table WHERE SUBSTRING_INDEX(domain, ',', 1) IN {'domain5', 'domain 2', 'domain6'} , but this only works for the first value before the comma (domain1)

+4
source share
3 answers

For SQL Server, use a custom function from CodeProject

0
source

with mysql you can concatenate your field and use regexp as follows:

 SELECT * FROM table1 WHERE CONCAT(',', domain, ',') REGEXP ',domain1,|,domain2,|,domain1,' 
0
source

Why don't you just use the LIKE operator with a percentage (%) wildcard.

 Select * From tablename where DOMAIN Like '%domain1%' or DOMAIN Like '%domain2%' or DOMAIN Like '%domain3%' 
0
source

All Articles