Problems with MySQL queries

Source: Internet
Author: User
, the field Tid holds the article tag ID, comma-delimited string, I now want to use the label to find out all the articles, such as "2", to find out all the Tid field has 2 of the article, now I use SELECT * from ' t_ms_article ' WHERE ' tid ' in (2) The statement can only be found to start with 2 of the article, and can not find out ' the "
I hope you can help me, I'm a rookie.


Reply to discussion (solution)

SELECT * from ' t_ms_article ' WHERE ' tid ' like '%2% ';

SELECT * from ' t_ms_article ' WHERE ' tid ' like '%2% ';


No, that way, you'll find 12 or 20 of these labels.

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, the solution, God 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.