9

I have following values in my sql column:-

a,b,c,d e,f

I want to check if b is present in the column.

vhu
  • 12,244
  • 11
  • 38
  • 48
Daljeet Singh
  • 704
  • 3
  • 7
  • 17

4 Answers4

23

You can use FIND_IN_SET():

FIND_IN_SET('b',yourcolumn) > 0

As an example to be used in a query:

SELECT * FROM yourtable WHERE FIND_IN_SET('b',yourcolumn) > 0;
vhu
  • 12,244
  • 11
  • 38
  • 48
5

you can use FIND_IN_SET()

FIND_IN_SET('a','a,b,c,d,e');

http://www.w3resource.com/mysql/string-functions/mysql-find_in_set-function.php

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
0

You can use a like clause on the column, for eg, if the column name contains these values in the users table you can use this query

select * from users where name like "%b%";
0

Try this:

select * from users where name like "%,b,%" OR name like "b,%" OR name like "%,b" ;
Ataboy Josef
  • 2,087
  • 3
  • 22
  • 27