David Jones

Using find_in_set() with spaces in between each item in the comma separated string

I was recently dealing with querying a database that has a column that is a comma separated string. So as you might have guessed I threw in the FIND_IN_SET() function and thought that would be enough to get the correct data from the database.

In any usual case this would have been sufficient but in this scenario each piece of data inside the comma separated string was also preceded with a space. I had to modify my query with the following.

FIND_IN_SET( "item", TRIM(REPLACE( column, " ", "")) )