您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MySQL查询的问题

2024/3/4 12:24:58发布22次查看
如图,字段tid保存的是文章标签id,用逗号分隔的字符串,我现在想通过标签,来查出来所有的文章,比如“2”,来查出所有tid字段里有2的文章,现在我用select * from `t_ms_article` where `tid` in (2)语句只能查出来以2开头的文章,而不能查出来‘1,2,3’这样的
希望能帮我一下,我是菜鸟
回复讨论(解决方案) select * from `t_ms_article` where `tid` like ‘%2%’;

select * from `t_ms_article` where `tid` like ‘%2%’;

不行的,这样的话会把12、20这样的标签也给查出来的
select * from `t_ms_article` where find_in_set('2', `tid`)

select * from `t_ms_article` where concat(',',`tid`,',') like ‘%,2,%’;
select * from `t_ms_article` where find_in_set('2', `tid`)

多谢,一下就解决了,大神请收下我的膝盖!
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product