Check if value exists in comma separated list

I have the following values โ€‹โ€‹in my sql column: -

a,b,c,de,f 

I want to check if column b present.

+7
sql mysql
source share
4 answers

You can use FIND_IN_SET () :

 FIND_IN_SET('b',yourcolumn) > 0 

As an example, which will be used in the request:

 SELECT * FROM yourtable WHERE FIND_IN_SET('b',yourcolumn) > 0; 
+10
source share

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

+4
source share

You can use a similar sentence in a column, for example, if the column name contains these values โ€‹โ€‹in the users table, you can use this query

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

Try the following:

 select * from users where name like "%,b,%" OR name like "b,%" OR name like "%,b" ; 
0
source share

All Articles