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
  • 11,534
  • 11
  • 37
  • 45
Daljeet Singh
  • 610
  • 3
  • 7
  • 16

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
  • 11,534
  • 11
  • 37
  • 45
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
  • 12,670
  • 19
  • 110
  • 153
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
  • 1,993
  • 2
  • 19
  • 27