我有一个名为 papers
的专栏在名为 products
的表中其值如下:
“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)
请注意,您的问题表明数据库设计有缺陷。您不应该在单个字符串列中存储多个整数值。相反,您应该将每个整数值放在单独的行中,可能在另一个表中,这将通过外键约束引用主表。推荐阅读:Is storing a delimited list in a database column really that bad? .
关于mysql SELECT 哪里喜欢和喜欢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64324456/