Anitha S
Anitha S

Reputation: 55

How to count comma separated values retrieved from database

My Sql Table Like this. Retrieve data from table and Count Particular data from this values.If given no is 6 means the count is 4.

+---------+-------------+-------------+
|      id |         Values            |
+---------+-------------+-------------+
|      11 |    1,2,4,5,6              |
|      12 |    1,2,6                  |
|      13 |    4,5,6                  |
|      14 |    2,3,6                  |
+---------+------------+--------------+

Upvotes: 2

Views: 851

Answers (1)

M Khalid Junaid
M Khalid Junaid

Reputation: 64476

You can use find_in_set to search the value from comma separated string

select count(*) total
from demo 
where find_in_set(6, `Values`) > 0;

Demo

Upvotes: 5

Related Questions