SQL查询以获取逗号分隔字段中存在值的行 [英] SQL query to fetch rows where a value is present in a comma separated field

查看:117
本文介绍了SQL查询以获取逗号分隔字段中存在值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查询是什么 -> 如何获取其列包含数据逗号分隔值的表内容如何检查该值是否存在于该列中(如果存在,则选择该产品的 ID)

what is the Query For -> How To Get The table content whose column consists of data comma sepreted value how to check is that value is present in that coloumn if present then select that ID of product

id   productname  poduct_cat_id
1    abc          2,3,4
2    def          3,4
3    efg          1,2,5

如何检查product_cat_id中的3并获取产品名称和id

How to check 3 in product_cat_id and get the product name and id

输出:结果[id]=1结果[产品名称]=abc

output: result[id]=1 result[productname]=abc

推荐答案

我同意 Phil 上面的评论.

I agree with Phil's comment above.

对于你的表,你可以使用 FIND_IN_SET 函数 -

For you table you can use FIND_IN_SET function -

SELECT * FROM table WHERE FIND_IN_SET(3, product_cat_id);

这篇关于SQL查询以获取逗号分隔字段中存在值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆