mysql SELECT where like and like



在一个名为products的表中,我有一个称为papers的列,其值如下:

"1,2,3,4,5,6";而在另一行中;3,4,5〃;

我想用php、启动这个查询

SELECT * from products where papers like "%5%" AND papers like "%3%" and papers like "%4%"

TL;博士

我想选择一个有多个字符串的列,忽略顺序

在MySQL中,您可以使用find_in_set():

select * 
from products 
where find_in_set('3', papers) and find_in_set('4', papers) and find_in_set('5', papers)

请注意,您的问题表明数据库设计存在缺陷。不应将多个整数值存储在单个字符串列中。相反,您应该将每个整数值放在一个单独的行中,可能放在另一个表中,该表将通过外键约束引用主表。推荐阅读:在数据库列中存储分隔列表真的有那么糟糕吗?。