Search code examples
mysqlsqlstringselectfind-in-set

FIND_IN_SET for part of string in Mysql


I need to make a query to a table in my database. Until now I was using FIND_IN_SET because I have strings like this: "twitter,bycicle,car".

Then, I could search by FIND_IN_SET("twitter", nameOfColumn)

But now, I need to search just part of each "set", for example: "twitter>10,bycicle,car"

It still works fine for bycicle and car but if I need to search for twitter, I cannot find it. What is the correct way to do this?


Solution

  • The following query would give you what you want, however use it with caution with respect to the data you have:

    SELECT *
    FROM table1
    WHERE col1 RLIKE 'twitter'
    

    Working Fiddle: http://sqlfiddle.com/#!2/66f538/1