Question

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.

Was it helpful?

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.

OTHER TIPS

Try this

SELECT COUNT(*)
FROM   ASD
WHERE ',' + content  + ','  like '%,89,%'

can you please try like this....i have seen something you want in this link http://www.randomsnippets.com/2008/10/05/how-to-count-values-with-mysql-queries/ ..hope it helps

  SELECT SUM(IF(content = 89, 1,0)) AS `MATCHED VALUE`,
    COUNT(content) AS `total`
    FROM asd
SELECT COUNT(*) as cnt FROM `asd` WHERE `content` LIKE '%,89,%' OR  `content` LIKE '89,%' OR `content` LIKE '%,89';

Check the SQL Fiddle : http://sqlfiddle.com/#!2/151c7/2/0

SELECT COUNT(*)
FROM   ASD
WHERE  content LIKE '%,89,%' OR
       content LIKE '%,89' OR
       content LIKE '89,%'

%,89,% - to match 89 in the middle of the content

%,89 - at the end of the content

89,% - at the beginning of the content

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top