Skip to content
Advertisement

Return rows with more than one comma separated value in a string

I have a table called contacts and in that table there is a field called contact_type.

contact_type is varchar and stores comma separated values in a sting like this:

^Media^,^Historical^

However only a few rows out of thousands have more than one value stored and I need to to run a query that will return only the rows with more than one so if it stores just ^Historical^ then it will be ignored.

I’m pretty much stumped on how to build a query like this. I assume it will contain something like this:

SELECT LENGTH(@css) - LENGTH( REPLACE( @css, ',', '') ) + 1;

Advertisement

Answer

Basically you need to select the records where contact_type contains a comma

select * from your_table
where instr(contact_type, ',') > 0
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement