1

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?

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
Biribu
  • 3,615
  • 13
  • 43
  • 79

2 Answers2

1

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

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
  • I didn't want to use LIKE because of that, maybe there are some similar strings and it make confusion. If I have no other way, I will use it – Biribu Dec 04 '14 at 11:01
  • @Biribu to slightly improve it, you may also try this: `RLIKE 'twitter.*,?'` – Aziz Shaikh Dec 04 '14 at 11:07
  • I have problems with words shorter than the contained in db. If I try with "twit", I get in return the row... – Biribu Dec 04 '14 at 11:26
0

Use LIKE operator:

SELECT *
FROM table1
WHERE nameOfColumn LIKE '%twitter%';
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83