Search code examples
mysqlsqlsearchlongtext

MySQL - count where id contained in a string


My table is called "asd"

I have this schema:

id        |  date     |  content |
AUTO_INC    DATETIME    LONGTEXT

now assuming content = 45,67,89,3,45,5

how do i search COUNT() in this table WHERE content CONTAINS 89 for example ?

i tryed SELECT COUNT() FROM asd WHERE content IN(89); but i got no results.


Solution

  • You can just use FIND_IN_SET

    SELECT COUNT(*) FROM `table` WHERE FIND_IN_SET(89,`content`);
    

    P.S. You need to read about many-to-many relations.