Home > Backend Development > PHP Tutorial > MySQL查询的问题

MySQL查询的问题

WBOY
Release: 2016-06-20 12:45:24
Original
968 people have browsed it

如图,字段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%’;
Copy after login
Copy after login

SELECT * FROM `t_ms_article` WHERE `tid` LIKE ‘%2%’;
Copy after login
Copy after login


不行的,这样的话会把12、20这样的标签也给查出来的

SELECT * FROM `t_ms_article` WHERE find_in_set('2', `tid`)
Copy after login
Copy after login

SELECT * FROM `t_ms_article` WHERE CONCAT(',',`tid`,',') LIKE ‘%,2,%’;
Copy after login

SELECT * FROM `t_ms_article` WHERE find_in_set('2', `tid`)
Copy after login
Copy after login


多谢,一下就解决了,大神请收下我的膝盖!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template