Php 如何编写查询以基于多值字段从表筛选器(WHERE子句)获取值?
我在MySQL中有一个产品表,字段如下所述Php 如何编写查询以基于多值字段从表筛选器(WHERE子句)获取值?,php,mysql,sql,Php,Mysql,Sql,我在MySQL中有一个产品表,字段如下所述 id productname price currency description category ------------------------------------------------------------------------- 34 xxxx 50 USD xyxyxyxyxyx 54,65 35 xxyy
id productname price currency description category
-------------------------------------------------------------------------
34 xxxx 50 USD xyxyxyxyxyx 54,65
35 xxyy 60 USD xyxyxyxyxyx 52,75
36 yyxx 70 USD xyxyxyxyxyx 24,85
37 yyyy 20 USD xyxyxyxyxyx 65,52
我所处的情况是,一种产品可以分为不同的类别。所以我使用逗号分隔符存储多个类别,如上表所示
现在我想从特定类别中检索产品,例如,检索类别52的产品
结果应该是这样的
id productname price currency description category
-------------------------------------------------------------------------
35 xxyy 60 USD xyxyxyxyxyx 52,75
37 yyyy 20 USD xyxyxyxyxyx 65,52
如何编写查询以获得此结果
事先非常感谢你 尝试使用该方法
不应在一列中存储多个值。。。数据库不是CSV文件的笔名。使用链接表。您应该更改数据库架构,并使用
product\u id
和category\u id
添加products\u categories
表。换句话说,请参阅规范化。
select * from tablename where FIND_IN_SET('52',category) > 0