MySQL Query-php Tutorial

Source: Internet
Author: User
For MySQL Query, The tid field stores the tag id of the article, which is a string separated by commas (,). now I want to use tags to find all the articles, such as "2 ", to find out that there are 2 articles IN all the tid fields. now I use the SELECT * FROM 't_ms_article 'Where 'tid' IN (2) statement to find only articles starting with 2, but it cannot be identified as '1, 2, 3 '.
Hope you can help me. I'm a Cainiao.


Reply to discussion (solution)

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

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


No. in this case, tags like 12 and 20 will also be found.

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`)


Thank you. I will solve it in a moment. please accept my knees!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.