[英]How to select a value from a table separated by a comma in mysql
ID tags
--------------------------------
1 1,2,3,4
2 2,3,4
3 4,22
4 2
this is my MySQL query 这是我的MySQL查询
"SELECT * FROM table_name WHERE tags LIKE '%2%'"
when I write above query to search only '2' in tags column it will give me '22' as a result. 当我在上面的查询中编写以仅在标签列中搜索“ 2”时,其结果为“ 22”。 So how do I prevent get '22' when I search only '2'.
因此,当我仅搜索“ 2”时如何防止得到“ 22”。 I need to get result as
我需要得到结果
ID tags
--------------------------------
1 1,2,3,4
2 2,3,4
4 2
SELECT * FROM table_name WHERE FIND_IN_SET(2, tags)
Try this MySQL query, 试试这个MySQL查询,
"SELECT * FROM table_name WHERE FIND_IN_SET(2, tags)"
It will help you 会帮你的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.