-1

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.

itsme
  • 48,972
  • 96
  • 224
  • 345

5 Answers5

6

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.

sectus
  • 15,605
  • 5
  • 55
  • 97
1

Try this

SELECT COUNT(*)
FROM   ASD
WHERE ',' + content  + ','  like '%,89,%'
bvr
  • 4,786
  • 1
  • 20
  • 24
1

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
BhavikKama
  • 8,566
  • 12
  • 94
  • 164
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

mishik
  • 9,973
  • 9
  • 45
  • 67
0
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

Goutam Pal
  • 1,763
  • 1
  • 10
  • 14