检查逗号分隔列表中是否存在值[重复]

时间:2021-02-10 04:27:33

This question already has an answer here:

这个问题在这里已有答案:

I have following values in my sql column:-

我的sql列中有以下值: -

a,b,c,d e,f

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

我想检查列中是否存在b。

4 个解决方案

#1


16  

You can use FIND_IN_SET():

您可以使用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;

#2


4  

you can use FIND_IN_SET()

你可以使用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

#3


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

您可以在列上使用like子句,例如,如果列名称在users表中包含这些值,则可以使用此查询

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

#4


0  

Try this:

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

#1


16  

You can use FIND_IN_SET():

您可以使用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;

#2


4  

you can use FIND_IN_SET()

你可以使用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

#3


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

您可以在列上使用like子句,例如,如果列名称在users表中包含这些值,则可以使用此查询

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

#4


0  

Try this:

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